Example usage for android.widget Button Button

List of usage examples for android.widget Button Button

Introduction

In this page you can find the example usage for android.widget Button Button.

Prototype

public Button(Context context) 

Source Link

Document

Simple constructor to use when creating a button from code.

Usage

From source file:org.digitalcampus.oppia.widgets.ResourceWidget.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);

    LinearLayout ll = (LinearLayout) getView().findViewById(R.id.widget_resource_object);
    String fileUrl = course.getLocation() + activity
            .getLocation(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));
    // show description if any
    String desc = activity/* w  w w .java 2 s  .  c o  m*/
            .getDescription(prefs.getString(PrefsActivity.PREF_LANGUAGE, Locale.getDefault().getLanguage()));

    TextView descTV = (TextView) getView().findViewById(R.id.widget_resource_description);
    if (desc.length() > 0) {
        descTV.setText(desc);
    } else {
        descTV.setVisibility(View.GONE);
    }

    File file = new File(fileUrl);
    setResourceFileName(file.getName());
    OnResourceClickListener orcl = new OnResourceClickListener(super.getActivity(), activity.getMimeType());
    // show image files
    if (activity.getMimeType().equals("image/jpeg") || activity.getMimeType().equals("image/png")) {
        ImageView iv = new ImageView(super.getActivity());
        Bitmap myBitmap = BitmapFactory.decodeFile(fileUrl);
        iv.setImageBitmap(myBitmap);
        LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
        ll.addView(iv, lp);
        iv.setTag(file);
        iv.setOnClickListener(orcl);
    } else {
        // add button to open other filetypes in whatever app the user has installed as default for that filetype
        Button btn = new Button(super.getActivity());
        btn.setText(super.getActivity().getString(R.string.widget_resource_open_file, file.getName()));
        btn.setTextAppearance(super.getActivity(), R.style.ButtonText);
        ll.addView(btn);
        btn.setTag(file);
        btn.setOnClickListener(orcl);
    }
}

From source file:br.org.funcate.dynamicforms.views.GPictureView.java

/**
 * @param fragmentDetail        the fragment detail  to use.
 * @param attrs                 attributes.
 * @param requestCode           the code for starting the activity with result.
 * @param parentView            parent/*from  w w  w  . ja  v a2  s .c  om*/
 * @param label                 label
 * @param pictures              the value are the ids and binary data of the images.
 * @param constraintDescription constraints
 */
public GPictureView(final FragmentDetail fragmentDetail, AttributeSet attrs, final int requestCode,
        LinearLayout parentView, String label, Map<String, Map<String, String>> pictures,
        String constraintDescription) {
    super(fragmentDetail.getActivity(), attrs);

    thumbnailWidth = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_width);
    thumbnailHeight = fragmentDetail.getActivity().getResources().getInteger(R.integer.thumbnail_height);

    mFragmentDetail = fragmentDetail;

    _pictures = pictures;

    PICTURE_VIEW_RESULT = requestCode;

    final FragmentActivity activity = fragmentDetail.getActivity();
    LinearLayout textLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(10, 10, 10, 10);
    textLayout.setPadding(10, 5, 10, 5);
    textLayout.setLayoutParams(layoutParams);
    textLayout.setOrientation(LinearLayout.VERTICAL);
    parentView.addView(textLayout);

    TextView textView = new TextView(activity);
    textView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    textView.setPadding(2, 2, 2, 2);
    String t = label.replace(UNDERSCORE, " ").replace(COLON, " ") + " " + constraintDescription;
    textView.setText(t);
    textView.setTextColor(activity.getResources().getColor(R.color.formcolor));
    textLayout.addView(textView);

    final Button button = new Button(activity);
    button.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    button.setPadding(15, 5, 15, 5);
    button.setText(R.string.take_picture);
    textLayout.addView(button);

    button.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {

            Intent cameraIntent = new Intent(activity, CameraActivity.class);

            cameraIntent.putExtra(FormUtilities.MAIN_APP_WORKING_DIRECTORY,
                    fragmentDetail.getWorkingDirectory());

            fragmentDetail.startActivityForResult(cameraIntent, requestCode);
        }
    });

    ScrollView scrollView = new ScrollView(activity);
    ScrollView.LayoutParams scrollLayoutParams = new ScrollView.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    scrollView.setLayoutParams(scrollLayoutParams);
    scrollView.setHorizontalScrollBarEnabled(true);
    scrollView.setOverScrollMode(HorizontalScrollView.OVER_SCROLL_ALWAYS);
    parentView.addView(scrollView);

    imageLayout = new LinearLayout(activity);
    LinearLayout.LayoutParams imageLayoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    imageLayout.setLayoutParams(imageLayoutParams);
    imageLayout.setPadding(15, 5, 15, 5);
    imageLayout.setOrientation(LinearLayout.HORIZONTAL);
    imageLayout.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
    scrollView.addView(imageLayout);

    updateValueForm();
    try {
        refresh(activity);
    } catch (Exception e) {
        //GPLog.error(this, null, e);
        e.printStackTrace();
        Toast.makeText(getContext(), e.getMessage(), Toast.LENGTH_LONG).show();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.ui.FeedHomeActivity.java

/** Called when the activity is first created. */
@Override/*from  w ww.  ja  va 2s .c om*/
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);
    mNfc = new Nfc(this);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;
    }

    mFeedViews = new ArrayList<FeedView>();
    mFeedViews.add(FeedViews.feedViewFrom("Feed", new FeedViewFragment()));
    mFeedViews.add(FeedViews.feedViewFrom("Apps", new AppsViewFragment()));
    mFeedViews.add(FeedViews.feedViewFrom("People", new FeedMembersFragment()));
    mFeedViews.add(new PresenceView());

    Intent intent = getIntent();
    String feed_name = null;
    String dyn_feed_uri = null;
    if (intent.getType() != null && intent.getType().equals(Feed.MIME_TYPE)) {
        Uri feedUri = getIntent().getData();
        feed_name = feedUri.getLastPathSegment();
        Maybe<Group> maybeG = Group.forFeedName(FeedHomeActivity.this, feed_name);
        try {
            Group g = maybeG.get();
            mGroupName = g.name;
            dyn_feed_uri = g.dynUpdateUri;
        } catch (Exception e) {
        }
    }

    if (dyn_feed_uri != null) {
        mNfc.share(NdefFactory.fromUri(dyn_feed_uri));
        Log.w(TAG, dyn_feed_uri);
    }

    mFeedUri = Feed.uriForName(feed_name);
    mColor = Feed.colorFor(feed_name);

    Bundle args = new Bundle();
    args.putParcelable(FeedViewFragment.ARG_FEED_URI, mFeedUri);
    mActionsFragment = new FeedActionsFragment();
    mActionsFragment.setArguments(args);

    for (FeedView f : mFeedViews) {
        f.getFragment().setArguments(args);
    }

    // TODO: Why is FeedActionsFragment.getActivity() null without this hack?
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    Fragment actions = getSupportFragmentManager().findFragmentByTag("feedActions");
    if (actions != null) {
        ft.remove(actions);
    }
    ft.add(mActionsFragment, "feedActions");
    ft.commit();

    PagerAdapter adapter = new FeedFragmentAdapter(getSupportFragmentManager(), mFeedUri);
    mFeedViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mFeedViewPager.setAdapter(adapter);
    mFeedViewPager.setOnPageChangeListener(this);
    mFeedViewPager.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (FeedView f : mFeedViews) {
        Button button = new Button(this);
        button.setText(f.getName());
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    doTitleBar(this, mGroupName);
    onPageSelected(0);
}

From source file:com.matthewtamlin.sliding_intro_screen_manual_testing.TestPageLock.java

/**
 * @param pageIndex//from w  w  w .  j a v  a2  s.  c om
 *       the index of the page to change to
 * @return creates a Button which navigates to a specific page
 */
private Button createGoToSpecificPageButton(final int pageIndex) {
    final Button button = new Button(this);
    button.setText("Go to page " + (pageIndex + 1));

    button.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final int startIndex = getIndexOfCurrentPage();
            goToPage(pageIndex);
            validateCommandPageChange(startIndex, pageIndex);
        }
    });

    return button;
}

From source file:com.normalexception.app.rx8club.fragment.category.CategoryFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_content, container, false);

    lv = (ListView) rootView.findViewById(R.id.mainlistview);

    //Get our click listener
    CategoryFragmentListener cl = new CategoryFragmentListener();

    // If the user clicked "New Posts" then we need to
    // handle things a little bit differently
    isNewTopicActivity = getArguments().getBoolean("isNewTopics", false);

    if (isNewTopicActivity)
        MainApplication.setState(AppState.State.NEW_POSTS, this);
    else//  w  w  w .  jav a  2  s . c  o m
        MainApplication.setState(AppState.State.CATEGORY, this);

    // We do not need to have a "New Thread" button if the
    // user clicked New Posts.
    if (!isNewTopicActivity && LoginFactory.getInstance().isLoggedIn()) {
        Button bv = new Button(getActivity());
        bv.setId(NEW_THREAD);
        bv.setOnClickListener(cl);
        bv.setText("New Thread");
        bv.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 10);
        lv.addHeaderView(bv);
    }

    // Footer has pagination information
    View v = inflater.inflate(R.layout.fragment_pagination, lv, false);
    FragmentUtils.registerHandlerToViewObjects(cl, (ViewGroup) v);
    lv.addFooterView(v);

    return rootView;
}

From source file:com.hichinaschool.flashcards.anki.multimediacard.activity.TranslationActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        boolean b = savedInstanceState.getBoolean(BUNDLE_KEY_SHUT_OFF, false);
        if (b) {/*from ww w  .  j  ava2s .c o m*/
            finishCancel();
            return;
        }
    }

    setContentView(R.layout.activity_translation);

    try {
        mSource = getIntent().getExtras().getString(EXTRA_SOURCE).toString();
    } catch (Exception e) {
        mSource = "";
    }

    // If translation fails this is a default - source will be returned.
    mTranslation = mSource;

    LinearLayout linearLayout = (LinearLayout) findViewById(R.id.MainLayoutInTranslationActivity);

    TextView tv = new TextView(this);
    tv.setText(getText(R.string.multimedia_editor_trans_poweredglosbe));
    linearLayout.addView(tv);

    TextView tvFrom = new TextView(this);
    tvFrom.setText(getText(R.string.multimedia_editor_trans_from));
    linearLayout.addView(tvFrom);

    mLanguageLister = new LanguagesListerGlosbe(this);

    mSpinnerFrom = new Spinner(this);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerFrom.setAdapter(adapter);
    linearLayout.addView(mSpinnerFrom);

    TextView tvTo = new TextView(this);
    tvTo.setText(getText(R.string.multimedia_editor_trans_to));
    linearLayout.addView(tvTo);

    mSpinnerTo = new Spinner(this);
    ArrayAdapter<String> adapterTo = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,
            mLanguageLister.getLanguages());
    adapterTo.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mSpinnerTo.setAdapter(adapterTo);
    linearLayout.addView(mSpinnerTo);

    Button btnDone = new Button(this);
    btnDone.setText(getText(R.string.multimedia_editor_trans_translate));
    btnDone.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            translate();
        }
    });

    linearLayout.addView(btnDone);

}

From source file:edu.stanford.mobisocial.dungbeetle.ui.wizard.ChangePictureActivity.java

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_feed_home);

    checked = new boolean[filterTypes.length];

    for (int x = 0; x < filterTypes.length; x++) {
        checked[x] = true;//from  w ww.j a v a2 s  . c  o  m
    }

    findViewById(R.id.btn_broadcast).setVisibility(View.GONE);
    mContactId = getIntent().getLongExtra("contact_id", -1);
    if (mContactId == -1) {
        Uri data = getIntent().getData();
        if (data != null) {
            try {
                mContactId = Long.parseLong(data.getLastPathSegment());
            } catch (NumberFormatException e) {
            }
        }
    }

    Bundle args = new Bundle();
    args.putLong("contact_id", mContactId);
    Fragment profileFragment = new ViewProfileFragment();
    profileFragment.setArguments(args);

    doTitleBar(this, "My Profile");
    mLabels.add("View");
    mLabels.add("Edit");
    mFragments.add(profileFragment);
    mFragments.add(new EditProfileFragment());

    Uri privateUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/private");
    mLabels.add("Notes");
    Fragment feedView = new FeedViewFragment();
    args = new Bundle(args);
    args.putParcelable(FeedViewFragment.ARG_FEED_URI, privateUri);
    feedView.setArguments(args);
    //mFragments.add(feedView);

    PagerAdapter adapter = new ViewFragmentAdapter(getSupportFragmentManager(), mFragments);
    mViewPager = (ViewPager) findViewById(R.id.feed_pager);
    mViewPager.setAdapter(adapter);
    mViewPager.setOnPageChangeListener(this);

    ViewGroup group = (ViewGroup) findViewById(R.id.tab_frame);
    int i = 0;
    for (String s : mLabels) {
        Button button = new Button(this);
        button.setText(s);
        button.setTextSize(18f);

        button.setLayoutParams(CommonLayouts.FULL_HEIGHT);
        button.setTag(i++);
        button.setOnClickListener(mViewSelected);

        group.addView(button);
        mButtons.add(button);
    }

    // Listen for future changes
    Uri feedUri;
    if (mContactId == Contact.MY_ID) {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/feeds/me");
    } else {
        feedUri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    }
    mProfileContentObserver = new ProfileContentObserver(mHandler);
    getContentResolver().registerContentObserver(feedUri, true, mProfileContentObserver);

    onPageSelected(0);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setMessage("Click on the avatar to take a profile picture of yourself.").setCancelable(false)
            .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {

                }
            });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:org.spinsuite.view.LV_Search.java

/**
 * Load Config//from w ww .ja v a2 s . co  m
 * @author <a href="mailto:yamelsenih@gmail.com">Yamel Senih</a> 18/03/2014, 22:07:43
 * @return void
 */
private void loadConfig() {
    if (m_SFA_Tab_ID != 0) {
        tabInfo = new InfoTab(getApplicationContext(), m_SFA_Tab_ID, true, null);
        viewList = new ArrayList<ViewIndex>();
        //   Set Parameter
        v_param = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, WEIGHT);
        //   Add Fields
        for (InfoField field : tabInfo.getFields()) {
            if (!field.IsDisplayed)
                continue;
            //   Add View to Layout
            addView(field);
        }
        //   Add Button
        Button btn_Search = new Button(this);
        btn_Search.setText(getResources().getString(R.string.msg_Search));
        //   Action
        btn_Search.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                m_criteria = new FilterValue();
                if (m_oldCriteria != null)
                    m_criteria = m_oldCriteria;
                //   Add Criteria
                addCriteriaQuery();
                load();
            }
        });
        //   Add Button
        llc_Search.addView(btn_Search, v_param);
    }
    //   Hide
    llc_Search.setVisibility(LinearLayout.GONE);
}

From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // it removes the title from the actionbar(more space for icons?)
    // this.getActionBar().setDisplayShowTitleEnabled(false);

    pixels5 = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 5, getResources().getDisplayMetrics());
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    LinearLayout parent = new LinearLayout(this);

    parent.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    parent.setOrientation(LinearLayout.VERTICAL);

    LinearLayout scrollViewParent = new LinearLayout(this);

    scrollViewParent.setLayoutParams(//from  w ww. j  a  v a2  s .co m
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    scrollViewParent.setOrientation(LinearLayout.HORIZONTAL);

    HorizontalScrollView predictionsHorizontalScrollView = new HorizontalScrollView(this);
    //predictionsHorizontalScrollView.setLayoutParams(new ViewGroup.LayoutParams());

    predictions = new LinearLayout(this);
    LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT);
    params.gravity = Gravity.CENTER_VERTICAL;
    predictions.setLayoutParams(params);

    predictions.setOrientation(LinearLayout.HORIZONTAL);

    resetPredictionsView(predictions, true);
    predictionsHorizontalScrollView.addView(predictions);

    saveButton = new Button(this);
    saveButton.setText("Send Feedback");

    predictionsHorizontalScrollView.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 10.0f));

    saveButton.setLayoutParams(
            new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT, 1.0f));

    saveButton.setVisibility(View.INVISIBLE);

    FrameLayout frameLayout = new FrameLayout(this);
    frameLayout
            .setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));
    frameLayout.addView(saveButton);

    loader = new ProgressBar(this);
    loader.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    loader.setIndeterminate(true);
    loader.setVisibility(ProgressBar.INVISIBLE);

    frameLayout.addView(loader);

    scrollViewParent.addView(predictionsHorizontalScrollView);
    scrollViewParent.addView(frameLayout);

    contentView = new MyView(this);
    parent.addView(scrollViewParent);
    parent.addView(contentView);

    setContentView(parent);

    otherLabelOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Log.e("Clicked", "Other Label label '" + (String) view.getTag() + "'");
            sendScreenshot(false, feedbackType, (String) view.getTag());
        }
    };

    mPaint = new Paint();
    mPaint.setAntiAlias(true);
    mPaint.setDither(true);
    mPaint.setColor(Color.BLACK);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.ROUND);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
    mPaint.setStrokeWidth(DEFAULT_BRUSH_SIZE);

    // Where did these magic numbers come from? What do they mean? Can I change them? ~TheOpenSourceNinja
    // Absolutely random numbers in order to see the emboss. asd! ~Valerio
    mEmboss = new EmbossMaskFilter(new float[] { 1, 1, 1 }, 0.4f, 6, 3.5f);

    mBlur = new BlurMaskFilter(5, BlurMaskFilter.Blur.NORMAL);

    if (isFirstTime()) {
        AlertDialog.Builder alert = new AlertDialog.Builder(this);

        alert.setTitle(R.string.app_name);
        alert.setMessage(R.string.app_description);
        alert.setNegativeButton(R.string.continue_button, new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int whichButton) {
                Toast.makeText(getApplicationContext(), R.string.here_is_your_canvas, Toast.LENGTH_SHORT)
                        .show();
            }
        });

        alert.show();
    } else {
        Toast.makeText(getApplicationContext(), R.string.here_is_your_canvas, Toast.LENGTH_SHORT).show();
    }

    loadFromIntents();
}

From source file:widgets.Graphical_Binary_New.java

public Graphical_Binary_New(tracerengine Trac, Activity context, String address, String name, int id,
        int dev_id, String state_key, String url, final String usage, String parameters, String model_id,
        int update, int widgetSize, int session_type, int place_id, String place_type, SharedPreferences params)
        throws JSONException {
    super(context, Trac, id, name, "", usage, widgetSize, session_type, place_id, place_type, mytag, container);
    this.Tracer = Trac;
    this.context = context;
    this.address = address;
    this.url = url;
    this.state_key = state_key;
    this.dev_id = dev_id;
    this.id = id;
    this.usage = usage;
    this.update = update;
    this.name = name;
    this.wname = name;
    this.myself = this;
    this.session_type = session_type;
    this.stateS = getResources().getText(R.string.State).toString();
    this.place_id = place_id;
    this.place_type = place_type;
    this.params = params;

    login = params.getString("http_auth_username", null);
    password = params.getString("http_auth_password", null);

    mytag = "Graphical_Binary_New(" + dev_id + ")";
    //get parameters      

    try {//from   ww w  . ja v  a 2s. c  o  m
        JSONObject jparam = new JSONObject(parameters.replaceAll("&quot;", "\""));
        value0 = jparam.getString("value0");
        value1 = jparam.getString("value1");
    } catch (Exception e) {
        value0 = "0";
        value1 = "1";
    }

    if (usage.equals("light")) {
        this.Value_0 = getResources().getText(R.string.light_stat_0).toString();
        this.Value_1 = getResources().getText(R.string.light_stat_1).toString();
    } else if (usage.equals("shutter")) {
        this.Value_0 = getResources().getText(R.string.shutter_stat_0).toString();
        this.Value_1 = getResources().getText(R.string.shutter_stat_1).toString();
    } else {
        this.Value_0 = value0;
        this.Value_1 = value1;
    }

    String[] model = model_id.split("\\.");
    type = model[0];
    Tracer.d(mytag,
            "model_id = <" + model_id + "> type = <" + type + "> value0 = " + value0 + "  value1 = " + value1);

    //state
    state = new TextView(context);
    state.setTextColor(Color.BLACK);
    state.setText("State :" + this.Value_0);

    final float scale = getContext().getResources().getDisplayMetrics().density;
    float dps = 40;
    int pixels = (int) (dps * scale + 0.5f);
    //first seekbar on/off
    ON = new Button(context);
    ON.setOnClickListener(this);
    ON.setHeight(pixels);
    //ON.setWidth(60);
    ON.setTag("ON");
    ON.setText(this.Value_1);
    ON.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    //ON.setBackgroundResource(R.drawable.boolean_on);
    //ON.setPadding(10, 0, 10, 0);

    OFF = new Button(context);
    OFF.setOnClickListener(this);
    OFF.setTag("OFF");
    OFF.setHeight(pixels);
    //OFF.setWidth(60);
    OFF.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
    //OFF.setBackgroundResource(R.drawable.boolean_off);
    OFF.setText(this.Value_0);
    //OFF.setPadding(0,10,0,10);

    super.LL_featurePan.addView(ON);
    super.LL_featurePan.addView(OFF);
    super.LL_infoPan.addView(state);

    handler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            if (activate) {
                Tracer.d(mytag, "Handler receives a request to die ");
                if (realtime) {
                    Tracer.get_engine().unsubscribe(session);
                    session = null;
                    realtime = false;
                }
                //That seems to be a zombie
                //removeView(background);
                myself.setVisibility(GONE);
                if (container != null) {
                    container.removeView(myself);
                    container.recomputeViewAttributes(myself);
                }
                try {
                    finalize();
                } catch (Throwable t) {
                } //kill the handler thread itself
            } else {
                try {
                    Bundle b = msg.getData();
                    if ((b != null) && (b.getString("message") != null)) {
                        if (b.getString("message").equals(value0)) {
                            //state.setText(stateS+value0);
                            state.setText(stateS + Value_0);
                            IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0));
                        } else if (b.getString("message").equals(value1)) {
                            //state.setText(stateS+value1);
                            state.setText(stateS + Value_1);
                            IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2));
                        }
                        state.setAnimation(animation);
                    } else {
                        if (msg.what == 2) {
                            Toast.makeText(getContext(), "Command Failed", Toast.LENGTH_SHORT).show();
                        } else if (msg.what == 9999) {
                            //state_engine send us a signal to notify value changed
                            if (session == null)
                                return;
                            String new_val = session.getValue();
                            Tracer.d(mytag, "Handler receives a new value <" + new_val + ">");
                            if (new_val.equals(value0)) {
                                state.setText(stateS + Value_0);
                                IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 0));
                            } else if (new_val.equals(value1)) {
                                state.setText(stateS + Value_1);
                                IV_img.setBackgroundResource(Graphics_Manager.Icones_Agent(usage, 2));
                            } else {
                                state.setText(stateS + new_val);
                            }
                        } else if (msg.what == 9998) {
                            // state_engine send us a signal to notify it'll die !
                            Tracer.d(mytag, "state engine disappeared ===> Harakiri !");
                            session = null;
                            realtime = false;
                            //removeView(background);
                            myself.setVisibility(GONE);
                            if (container != null) {
                                container.removeView(myself);
                                container.recomputeViewAttributes(myself);
                            }
                            try {
                                finalize();
                            } catch (Throwable t) {
                            } //kill the handler thread itself
                        }
                    }

                } catch (Exception e) {
                    Tracer.e(mytag, "Handler error for device " + wname);
                    e.printStackTrace();
                }
            }
        }
    };
    //================================================================================
    /*
     * New mechanism to be notified by widgetupdate engine when our value is changed
     * 
     */
    WidgetUpdate cache_engine = WidgetUpdate.getInstance();
    if (cache_engine != null) {
        session = new Entity_client(dev_id, state_key, mytag, handler, session_type);
        if (Tracer.get_engine().subscribe(session)) {
            realtime = true; //we're connected to engine
            //each time our value change, the engine will call handler
            handler.sendEmptyMessage(9999); //Force to consider current value in session
        }

    }
    //================================================================================
    //updateTimer();   //Don't use anymore cyclic refresh....   

}