Example usage for android.widget ImageView setImageResource

List of usage examples for android.widget ImageView setImageResource

Introduction

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

Prototype

@android.view.RemotableViewMethod(asyncImpl = "setImageResourceAsync")
public void setImageResource(@DrawableRes int resId) 

Source Link

Document

Sets a drawable as the content of this ImageView.

Usage

From source file:com.insthub.O2OMobile.Activity.D1_OrderActivity.java

private void showOrderDialog(boolean isSucceed, orderacceptResponse response) {
    LayoutInflater inflater = LayoutInflater.from(D1_OrderActivity.this);
    View view = inflater.inflate(R.layout.d1_order_dialog, null);
    mOrderDialog = new Dialog(D1_OrderActivity.this, R.style.dialog);
    mOrderDialog.setContentView(view);//from  w ww  .  j a  v a 2 s  .  c om
    mOrderDialog.setCanceledOnTouchOutside(false);
    mOrderDialog.show();

    Button order_dialog_button = (Button) view.findViewById(R.id.order_dialog_button);
    ImageView order_dialog_icon = (ImageView) view.findViewById(R.id.order_dialog_icon);
    TextView order_dialog_text = (TextView) view.findViewById(R.id.order_dialog_text);
    TextView order_dialog_error_text = (TextView) view.findViewById(R.id.order_dialog_error_text);

    if (isSucceed) {
        order_dialog_icon.setImageResource(R.drawable.b2_selected_icon);
        order_dialog_text.setText(getString(R.string.receive_order_success));
        order_dialog_text.setTextColor(Color.parseColor("#39BCED"));
    } else {
        order_dialog_icon.setImageResource(R.drawable.d3_failed);
        order_dialog_text.setText(getString(R.string.receive_order_fail));
        order_dialog_text.setTextColor(Color.parseColor("#f65858"));
        order_dialog_error_text.setText(response.error_desc);
    }

    order_dialog_button.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            mOrderDialog.dismiss();
        }
    });
}

From source file:org.nla.tarotdroid.lib.ui.GameSetHistoryActivity.java

/**
 * Starts the whole Facebook post process.
 * /*from   w  w w  .  j  a  v  a 2 s  . com*/
 * @param session
 */
private void launchPostProcess(final Session session) {

    LayoutInflater inflater = getLayoutInflater();
    View layout = inflater.inflate(R.layout.toast, (ViewGroup) findViewById(R.id.toast_layout_root));

    ImageView image = (ImageView) layout.findViewById(R.id.image);
    image.setImageResource(R.drawable.icon_facebook_released);
    TextView text = (TextView) layout.findViewById(R.id.text);
    text.setText("Publication en cours");

    Toast toast = new Toast(getApplicationContext());
    toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
    toast.setDuration(Toast.LENGTH_LONG);
    toast.setView(layout);
    toast.show();

    Request request = Request.newMeRequest(session, new Request.GraphUserCallback() {

        @Override
        public void onCompleted(GraphUser user, Response response) {
            if (session == Session.getActiveSession()) {
                if (user != null) {
                    int notificationId = FacebookHelper
                            .showNotificationStartProgress(GameSetHistoryActivity.this);
                    AppContext.getApplication().getNotificationIds().put(tempGameSet.getUuid(), notificationId);

                    AppContext.getApplication().setLoggedFacebookUser(user);
                    UpSyncGameSetTask task = new UpSyncGameSetTask(GameSetHistoryActivity.this, progressDialog);
                    task.setCallback(GameSetHistoryActivity.this.upSyncCallback);
                    task.execute(tempGameSet);
                    currentRunningTask = task;
                }
            }
            if (response.getError() != null) {
                // //progressDialog.dismiss();
                // Session newSession = new
                // Session(GameSetHistoryActivity.this);
                // Session.setActiveSession(newSession);
                // newSession.openForPublish(new
                // Session.OpenRequest(GameSetHistoryActivity.this).setPermissions(Arrays.asList("publish_actions",
                // "email")).setCallback(facebookSessionStatusCallback));
            }
        }
    });
    request.executeAsync();
}

From source file:com.first.akashshrivastava.showernow.ShowerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_shower_activity);

    /*Launching BootReceiver to test
    Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class);
    startActivity(playIntent);//from   www .j a va 2  s  .  c o m
    */

    //Mobile ads initialization....The long number is the AdID, can be found on AdMob -  ca-app-pub-8782530512283806/2988799979
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979");
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    //Facebook SDK initialization...
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    shareDialog = new ShareDialog(this);

    mDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAuth = FirebaseAuth.getInstance();

    final ImageView genderImage = (ImageView) findViewById(R.id.imageGender);

    guyText = (TextView) findViewById(R.id.guyText);

    topText = (TextView) findViewById(R.id.textView2);

    SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);

    extraAge = prefs.getInt("age", 0);
    extraFluffiness = prefs.getString("fluffiness", "");
    extraGender = prefs.getString("gender", "");
    extraOldTime = prefs.getLong("time", 0);
    extraSteps = prefs.getFloat("stepsBoot", 0);

    switch (extraGender) {
    case "male":
        genderImage.setImageResource(R.drawable.male_white_outline);
        break;
    case "female":
        genderImage.setImageResource(R.drawable.female_white_outline);
        break;
    case "other":
        genderImage.setImageResource(R.drawable.other_white_outline);
        break;
    }

    genderImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) { //set alarm
            //Swith ccase
            switch (event.getAction()) {

            case MotionEvent.ACTION_UP:
                // PRESSED ..PRESSED

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

                //Resets the wave after shower..this is not getting called for some reason....
                waveProgressbar.setCurrent(0, "");
                guyText.setText("0 %");
                waveProgressbar.setVisibility(View.INVISIBLE);

                topText.setText("You have showered! \n When the wave hits 100% its time for your next shower ");

                if (fluffiness != null && gotSteps) {
                    Calendar cal = Calendar.getInstance();
                    Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
                    activate.putExtra("age", age);
                    activate.putExtra("fluffiness", fluffiness);
                    activate.putExtra("gender", gender);
                    activate.putExtra("steps", steps);
                    activate.putExtra("time", System.currentTimeMillis());

                    AlarmManager alarms;
                    PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                            FLAG_CANCEL_CURRENT);
                    alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
                    alarms.cancel(alarmIntent);

                    alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60,
                            alarmIntent);//sets the alarm

                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Steps").setValue(steps);//sets old steps
                    oldSteps = steps;
                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Time").setValue(System.currentTimeMillis());
                    oldTime = System.currentTimeMillis();
                    newUser = false;

                    SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sharedPref.edit();
                    editor.putInt("age", age);
                    editor.putString("fluffiness", fluffiness);
                    editor.putString("gender", gender);
                    editor.putFloat("steps", steps);
                    editor.putLong("time", System.currentTimeMillis());
                    editor.putFloat("stepsBoot", 0);
                    editor.putBoolean("bootStart", true);
                    editor.apply();

                } else if (!gotSteps) {
                    Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show();
                }
                return true; // if you want to handle the touch event

            case MotionEvent.ACTION_DOWN:
                // RELEASED..RELEASED..

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline_pressed);

                }

                return true; // if you want to handle the touch event
            }
            //Switch case end bracket

            return false;
        }

    });

    createWave();
    setMenuColor();
    setupStepcount();
    setWaveHeight();

    FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity
    editDetails.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            /*
            Fragment fragment = new Fragment();
            FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(ShowerActivity.java);
            transaction.addToBackStack(ShowerActivity.java);
            transaction.commit();
                    
            */
            //Fragment B at pos 2 should open when edit details is pressed..
            Intent i = new Intent(ShowerActivity.this, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
        }
    });

    FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account);
    fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dialog();
        }
    });

    FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item);
    fabMenuItem1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);??
            PackageManager pm = ShowerActivity.this.getPackageManager();
            pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
                    
            stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/

            //mFirebaseAuth.getCurrentUser().getUid() =null;

            SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("age", 0);
            editor.putString("fluffiness", "");
            editor.putString("gender", "");
            editor.putFloat("steps", 0);
            editor.putLong("time", 0);
            editor.putFloat("stepsBoot", 0);
            editor.putBoolean("bootStart", false);
            editor.apply();

            Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
            PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                    FLAG_CANCEL_CURRENT);

            AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarms.cancel(alarmIntent);

            stopService(new Intent(ShowerActivity.this, StepCountService.class));

            mFirebaseAuth.getInstance().signOut();
            Intent i = new Intent(ShowerActivity.this, LoginActivity.class);
            startActivity(i);
        }
    });

    final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton);
    shareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n";
            String shareSubString = "An app that tells you when you should shower and apparently keeps you clean";
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString);
            shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(shareIntent, " Share using the following"));

        }
    });

    mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snap) {

            try {
                if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty()))
                        && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                                .getValue().toString().equalsIgnoreCase("female")) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("male")) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("other")) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
            age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                    .child("Age").getValue().toString());//gotta get int

            fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();
            gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();

            if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) {
                oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time")
                        .getValue(Long.class);
                oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps")
                        .getValue(float.class);

            } else {
                newUser = true;
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

From source file:org.sirimangalo.meditationplus.AdapterMed.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {

    View rowView;/*from ww  w . j  av  a  2s. c  om*/

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        rowView = inflater.inflate(R.layout.list_item_med, parent, false);
    } else {
        rowView = convertView;
    }

    JSONObject p = values.get(position);

    TextView walk = (TextView) rowView.findViewById(R.id.one_walking);
    TextView sit = (TextView) rowView.findViewById(R.id.one_sitting);
    ImageView status = (ImageView) rowView.findViewById(R.id.one_status);
    TextView name = (TextView) rowView.findViewById(R.id.one_med);
    ImageView flag = (ImageView) rowView.findViewById(R.id.one_flag);

    View anuView = rowView.findViewById(R.id.anumodana_shell);
    TextView anuText = (TextView) rowView.findViewById(R.id.anumodana);

    try {
        String wo = p.getString("walking");
        String so = p.getString("sitting");
        int wi = Integer.parseInt(wo);
        int si = Integer.parseInt(so);
        int ti = Integer.parseInt(p.getString("start"));
        int ei = Integer.parseInt(p.getString("end"));

        long nowL = System.currentTimeMillis() / 1000;

        int now = (int) nowL;

        boolean finished = false;

        String ws = "0";
        String ss = "0";

        if (ei > now) {

            float secs = now - ti;

            if (secs > wi * 60 || wi == 0) { //walking done
                float ssecs = (int) (secs - (wi * 60));
                if (ssecs < si * 60) // still sitting
                    ss = Integer.toString((int) Math.floor(si - ssecs / 60));
                status.setImageResource(R.drawable.sitting_icon);
            } else { // still walking
                ws = Integer.toString((int) Math.floor(wi - secs / 60));
                ss = so;
                status.setImageResource(R.drawable.walking_icon);
            }

            ws += "/" + wo;
            ss += "/" + so;
        } else {
            ws = wo;
            ss = so;

            double age = 1 - (now - ei) / MAX_AGE;

            String ageColor = Integer.toHexString((int) (255 * age));

            if (ageColor.length() == 1)
                ageColor = "0" + ageColor;

            int alpha = Color.parseColor("#" + ageColor + "000000");

            walk.setTextColor(alpha);
            sit.setTextColor(alpha);
            name.setTextColor(alpha);
            status.setAlpha((float) age);
            flag.setAlpha((float) age);

        }

        walk.setText(ws);
        sit.setText(ss);

        if (p.has("country")) {
            int id = context.getResources().getIdentifier("flag_" + p.getString("country").toLowerCase(),
                    "drawable", context.getPackageName());
            flag.setImageResource(id);
            flag.setVisibility(View.VISIBLE);
        }

        final String username = p.getString("username");
        final String edit = p.getString("can_edit");
        name.setText(username);

        name.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                context.showProfile(username);
            }
        });

        String type = p.getString("type");
        if ("love".equals(type))
            status.setImageResource(R.drawable.love_icon);

        String anu = p.getString("anumodana");
        if (!anu.equals("0"))
            anuText.setText(anu);

        if (p.getString("anu_me").equals("1")) {
            anuText.setTextColor(0xFF00BB00);
            anuText.setTypeface(null, Typeface.BOLD);
        }

        final String sid = p.getString("sid");

        anuView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Log.d(TAG, "anu clicked");
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
                String loggedUsername = prefs.getString("username", "");
                String loginToken = prefs.getString("login_token", "");
                ArrayList<NameValuePair> nvp = new ArrayList<NameValuePair>();
                nvp.add(new BasicNameValuePair("form_id", "anumed_" + sid));
                nvp.add(new BasicNameValuePair("login_token", loginToken));
                nvp.add(new BasicNameValuePair("submit", "Refresh"));
                nvp.add(new BasicNameValuePair("username", loggedUsername));
                nvp.add(new BasicNameValuePair("source", "android"));
                PostTaskRunner postTask = new PostTaskRunner(postHandler, context);
                postTask.doPostTask(nvp);

            }
        });

    } catch (Exception e) {
        e.printStackTrace();
    }
    return rowView;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
 * Shrinks the image in the passed file to the specified dimensions, and places the image
 * in the passed view. The bitmap is returned.
 * /*from  w w  w  .j a  v  a 2 s .co  m*/
 * @param file
 * @param destView
 * @param maxWidth
 * @param maxHeight
 * @param exact
 * 
 * @return
 */
public static Bitmap fetchFileIntoImageView(File file, ImageView destView, int maxWidth, int maxHeight,
        boolean exact) {

    Bitmap bm = null; // resultant Bitmap (which we will return) 

    // Get the file, if it exists. Otherwise set 'help' icon and exit.
    if (!file.exists()) {
        if (destView != null)
            destView.setImageResource(android.R.drawable.ic_menu_help);
        return null;
    }

    bm = shrinkFileIntoImageView(destView, file.getPath(), maxWidth, maxHeight, exact);

    return bm;
}

From source file:com.conferenceengineer.android.iosched.ui.SessionDetailFragment.java

@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void setOrAnimateIconTo(final ImageView imageView, final int imageResId, boolean animate) {
    if (UIUtils.hasICS() && imageView.getTag() != null) {
        if (imageView.getTag() instanceof Animator) {
            Animator anim = (Animator) imageView.getTag();
            anim.end();// ww w .  j a va2s. c o  m
            imageView.setAlpha(1f);
        }
    }

    animate = animate && UIUtils.hasICS();
    if (animate) {
        int duration = getResources().getInteger(android.R.integer.config_shortAnimTime);

        Animator outAnimator = ObjectAnimator.ofFloat(imageView, View.ALPHA, 0f);
        outAnimator.setDuration(duration / 2);
        outAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setImageResource(imageResId);
            }
        });

        AnimatorSet inAnimator = new AnimatorSet();
        inAnimator.setDuration(duration);
        inAnimator.playTogether(ObjectAnimator.ofFloat(imageView, View.ALPHA, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_X, 0f, 1f),
                ObjectAnimator.ofFloat(imageView, View.SCALE_Y, 0f, 1f));

        AnimatorSet set = new AnimatorSet();
        set.playSequentially(outAnimator, inAnimator);
        set.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                imageView.setTag(null);
            }
        });
        imageView.setTag(set);
        set.start();
    } else {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                imageView.setImageResource(imageResId);
            }
        });
    }
}

From source file:com.mobicage.rogerthat.plugins.messaging.ServiceMessageDetailActivity.java

private void setAvatar(ImageView imageView, final String email) {
    if (FriendsPlugin.SYSTEM_FRIEND.equals(email)) {
        imageView.setImageResource(R.drawable.ic_dashboard);
    } else {//from   w  w  w  .j a v a 2s .co m
        imageView.setImageBitmap(mFriendsPlugin.getAvatarBitmap(email, true));
        final SafeViewOnClickListener listener = getFriendDetailOnClickListener(email);
        if (listener != null)
            imageView.setOnClickListener(listener);
    }
}

From source file:com.dinkbit.slidingtabexample.ui.tabs.SlidingTabLayout.java

private void populateTabStrip() {

    //If you don need textView or imageView, you can comment related code lines :)

    //We do a cast to work with our custom adapter
    final MainActivity.SectionsPagerAdapter adapter = (MainActivity.SectionsPagerAdapter) mViewPager
            .getAdapter();/*from w  w w. j ava 2  s. c o  m*/
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;
        TextView tabTitleView = null;
        ImageView tabImageView = null;

        if (mTabViewLayoutId != 0) {
            // If there is a custom tab view layout id set, try and inflate it
            tabView = LayoutInflater.from(getContext()).inflate(mTabViewLayoutId, mTabStrip, false);
            tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);
            tabImageView = (ImageView) tabView.findViewById(mTabViewImageViewId);
        }

        if (tabView == null) {
            tabView = createDefaultTabView(getContext());
        }

        if (tabTitleView == null && TextView.class.isInstance(tabView)) {
            tabTitleView = (TextView) tabView;
        }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        if (tabTitleView != null) {

            tabTitleView.setText(adapter.getPageTitle(i));

        } else {
            Log.e(LOG_TAG, "No view for tabTitleView found in TabViewLayout resource o_O!");
        }

        if (tabImageView != null) {

            tabImageView.setImageResource(android.R.drawable.ic_dialog_dialer);
            //TODO::Set ImageResource using your adapter, like this:
            //tabImageView.setImageResource(adapter.getPageIcon(i));

        } else {
            Log.e(LOG_TAG, "No view for tabImageView found in TabViewLayout resource o_O!");
        }

        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
    }
}

From source file:com.speed.traquer.app.TraqComplaintTaxi.java

private void PromptCustomDialog() {

    // Create custom dialog object
    final Dialog dialog = new Dialog(TraqComplaintTaxi.this);
    // Include dialog.xml file
    dialog.setContentView(R.layout.activity_submit_social);
    // Set dialog title
    dialog.setTitle("Submit via");

    // set values for custom dialog components - text, image and button
    final TextView twitterText = (TextView) dialog.findViewById(R.id.textTwitterDialog);
    twitterText.setText("Twitter");

    final TextView facebookText = (TextView) dialog.findViewById(R.id.textFacebookDialog);
    facebookText.setText("Facebook");

    final TextView defaultText = (TextView) dialog.findViewById(R.id.textDefaultDialog);
    defaultText.setText("Default");
    defaultText.setTextColor(getResources().getColor(R.color.Orange));

    final TextView smsText = (TextView) dialog.findViewById(R.id.textSMSDialog);
    smsText.setText("SMS");

    final ImageView image = (ImageView) dialog.findViewById(R.id.imageDialog);
    image.setImageResource(R.drawable.icon_twitter);

    final ImageView imageFb = (ImageView) dialog.findViewById(R.id.imageDialogFb);
    imageFb.setImageResource(R.drawable.ic_fb_grey);

    final ImageView imageDefault = (ImageView) dialog.findViewById(R.id.imageDialogDefault);
    imageDefault.setImageResource(R.drawable.icon_traquer_color);
    isDefaultSelected = true;/*w  w w .j  a  v a2  s  . c  o m*/

    final ImageView imageSMS = (ImageView) dialog.findViewById(R.id.imageDialogSMS);
    imageSMS.setImageResource(R.drawable.icon_sms);

    dialog.show();

    //Retrieve form info
    taxi_id = inputTaxi.getText().toString().toUpperCase();
    taxi_id = taxi_id.replace(" ", "");
    taxi_comp = actv_comp_taxi.getText().toString();
    taxi_driver = taxiDriver.getText().toString();
    taxi_license = taxiLic.getText().toString();
    loc_frm = actv_from.getText().toString();
    loc_to = actv_to.getText().toString();
    dateBus = editDate.getText().toString();
    timeBus = editTime.getText().toString();
    curr_time = editCurrTime.getText().toString();
    user_name = SaveSharedPreference.getUserName(TraqComplaintTaxi.this);

    //Twitter Button
    final RelativeLayout twitterLogin = (RelativeLayout) dialog.findViewById(R.id.twitterImageButton);
    twitterLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isTwitterSelected) {
                image.setImageResource(R.drawable.icon_twitter);
                twitterText.setTextColor(getResources().getColor(R.color.DarkGray));
                isTwitterSelected = false;
            } else {
                loginToTwitter();
                image.setImageResource(R.drawable.icon_twitter_blue);
                twitterText.setTextColor(getResources().getColor(R.color.TwitterBlue));
                isTwitterSelected = true;
            }

        }
    });

    //facebook Button
    final RelativeLayout facebookLogin = (RelativeLayout) dialog.findViewById(R.id.facebookImageButton);
    facebookLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isFacebookSelected) {
                imageFb.setImageResource(R.drawable.ic_fb_grey);
                if (fbUserName != null)
                    facebookText.setText("Facebook");

                facebookText.setTextColor(getResources().getColor(R.color.DarkGray));
                isFacebookSelected = false;
            } else {

                //loginToTwitter();
                // start Facebook Login
                loginToFacebook();
                if (fbUserName != null)
                    facebookText.setText(fbUserName);
                imageFb.setImageResource(R.drawable.ic_fb_blue);
                facebookText.setTextColor(getResources().getColor(R.color.TwitterBlue));
                isFacebookSelected = true;
            }

        }
    });

    //SMS Button
    final RelativeLayout SMSLogin = (RelativeLayout) dialog.findViewById(R.id.smsImageButton);
    SMSLogin.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isSmsSelected) {
                imageSMS.setImageResource(R.drawable.icon_sms);
                smsText.setTextColor(getResources().getColor(R.color.DarkGray));
                isSmsSelected = false;
            } else {
                imageSMS.setImageResource(R.drawable.icon_sms_color);
                smsText.setTextColor(getResources().getColor(R.color.Orange));
                isSmsSelected = true;
            }

        }
    });

    /*/Default Button
    final RelativeLayout defaultLogin = (RelativeLayout)dialog.findViewById(R.id.defaultImageButton);
    defaultLogin.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if(isDefaultSelected)
        {
            imageDefault.setImageResource(R.drawable.icon_traquer_color);
            defaultText.setTextColor(getResources().getColor(R.color.Orange));
            isDefaultSelected = false;
        }
        else
        {
            imageDefault.setImageResource(R.drawable.icon_traquer_color);
            defaultText.setTextColor(getResources().getColor(R.color.Orange));
            isDefaultSelected = true;
        }
            
    }
    });*/

    //Submit Button
    Button declineButton = (Button) dialog.findViewById(R.id.submitButton);
    // if decline button is clicked, close the custom dialog
    declineButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            //submit complaint
            isSubmitButtonClicked = true;
            if (isNetworkConnected() == true) {
                Toast.makeText(TraqComplaintTaxi.this, "Complaint sent. Thank you for taking action!",
                        Toast.LENGTH_SHORT).show();

                //Combine Strings for Twitter Status

                String status = taxi_id + ", " + taxi_comp + " taxi is speeding with " + speedTaxiExceed
                        + "km/h at " + Double.toString(gLatitude) + "N, " + Double.toString(gLongitude)
                        + "E, " + curr_time + " @aduanSPAD @MyTraquer #Traquer";

                finalStatus = status;

                if (isFacebookSelected) {
                    //share to facebook
                    ShareToFacebook(status);
                    //publishFeedDialog();
                }

                if (isTwitterSelected) {

                    //Toast.makeText(TraqComplaintTaxi.this, Long.toString(twitterID) + userName, Toast.LENGTH_SHORT).show();

                    // Check for blank text
                    if (status.trim().length() > 0) {
                        // update status
                        if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR1) {
                            new updateTwitterStatus().execute(status);
                        }

                        else
                            new updateTwitterStatus().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, status);

                    } else {
                        // EditText is empty
                        Toast.makeText(getApplicationContext(), "Please enter status message",
                                Toast.LENGTH_SHORT).show();
                    }

                } else {
                    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB_MR1)
                        new InsertForm().execute();
                    else
                        new InsertForm().executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);

                }

                // Close dialog
                dialog.dismiss();

            } else {
                if (isSmsSelected) {
                    Log.i("Clicks", "You clicked sent.");

                    Intent sendIntent = new Intent(Intent.ACTION_VIEW);
                    sendIntent.putExtra("address", "15888");
                    sendIntent.putExtra("sms_body",
                            "SPAD Aduan " + taxi_id + ", " + taxi_comp + " taxi is speeding with "
                                    + speedTaxiExceed + "km/h at " + Double.toString(gLatitude) + "N, "
                                    + Double.toString(gLongitude) + "E, " + curr_time + " - Traquer");
                    sendIntent.setType("vnd.android-dir/mms-sms");
                    startActivity(sendIntent);

                    //1800-88-7723
                } else {
                    Toast.makeText(TraqComplaintTaxi.this,
                            "Failed to send. Please check your network connection.", Toast.LENGTH_SHORT).show();
                }
            }

        }

    });
    //TraqComplaintTaxi.this.showDialog(ALERT_DIALOG);
}

From source file:com.goftagram.telegram.ui.Components.PasscodeView.java

public PasscodeView(final Context context) {
    super(context);

    setWillNotDraw(false);//from  ww w. j av a2s  . c  om
    setVisibility(GONE);

    backgroundFrameLayout = new FrameLayout(context);
    addView(backgroundFrameLayout);
    LayoutParams layoutParams = (LayoutParams) backgroundFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    backgroundFrameLayout.setLayoutParams(layoutParams);

    passwordFrameLayout = new FrameLayout(context);
    addView(passwordFrameLayout);
    layoutParams = (LayoutParams) passwordFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    passwordFrameLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setImageResource(R.drawable.passcode_logo);
    passwordFrameLayout.addView(imageView);
    layoutParams = (LayoutParams) imageView.getLayoutParams();
    if (AndroidUtilities.density < 1) {
        layoutParams.width = AndroidUtilities.dp(30);
        layoutParams.height = AndroidUtilities.dp(30);
    } else {
        layoutParams.width = AndroidUtilities.dp(40);
        layoutParams.height = AndroidUtilities.dp(40);
    }
    layoutParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    layoutParams.bottomMargin = AndroidUtilities.dp(100);
    imageView.setLayoutParams(layoutParams);

    passcodeTextView = new TextView(context);
    passcodeTextView.setTextColor(0xffffffff);
    passcodeTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    passcodeTextView.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordFrameLayout.addView(passcodeTextView);
    layoutParams = (LayoutParams) passcodeTextView.getLayoutParams();
    layoutParams.width = LayoutHelper.WRAP_CONTENT;
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.bottomMargin = AndroidUtilities.dp(62);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passcodeTextView.setLayoutParams(layoutParams);

    passwordEditText2 = new AnimatingTextView(context);
    passwordFrameLayout.addView(passwordEditText2);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText2.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText2.setLayoutParams(layoutParams);

    passwordEditText = new EditText(context);
    passwordEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
    passwordEditText.setTextColor(0xffffffff);
    passwordEditText.setMaxLines(1);
    passwordEditText.setLines(1);
    passwordEditText.setGravity(Gravity.CENTER_HORIZONTAL);
    passwordEditText.setSingleLine(true);
    passwordEditText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    passwordEditText.setTypeface(Typeface.DEFAULT);
    passwordEditText.setBackgroundDrawable(null);
    AndroidUtilities.clearCursorDrawable(passwordEditText);
    passwordFrameLayout.addView(passwordEditText);
    layoutParams = (FrameLayout.LayoutParams) passwordEditText.getLayoutParams();
    layoutParams.height = LayoutHelper.WRAP_CONTENT;
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.leftMargin = AndroidUtilities.dp(70);
    layoutParams.rightMargin = AndroidUtilities.dp(70);
    layoutParams.bottomMargin = AndroidUtilities.dp(6);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL;
    passwordEditText.setLayoutParams(layoutParams);
    passwordEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
            if (i == EditorInfo.IME_ACTION_DONE) {
                processDone(false);
                return true;
            }
            return false;
        }
    });
    passwordEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

        }

        @Override
        public void afterTextChanged(Editable s) {
            if (passwordEditText.length() == 4 && UserConfig.passcodeType == 0) {
                processDone(false);
            }
        }
    });
    if (android.os.Build.VERSION.SDK_INT < 11) {
        passwordEditText.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
            public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
                menu.clear();
            }
        });
    } else {
        passwordEditText.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
            public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public void onDestroyActionMode(ActionMode mode) {
            }

            public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                return false;
            }

            public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                return false;
            }
        });
    }

    checkImage = new ImageView(context);
    checkImage.setImageResource(R.drawable.passcode_check);
    checkImage.setScaleType(ImageView.ScaleType.CENTER);
    checkImage.setBackgroundResource(R.drawable.bar_selector_lock);
    passwordFrameLayout.addView(checkImage);
    layoutParams = (LayoutParams) checkImage.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(60);
    layoutParams.height = AndroidUtilities.dp(60);
    layoutParams.bottomMargin = AndroidUtilities.dp(4);
    layoutParams.rightMargin = AndroidUtilities.dp(10);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.RIGHT;
    checkImage.setLayoutParams(layoutParams);
    checkImage.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            processDone(false);
        }
    });

    FrameLayout lineFrameLayout = new FrameLayout(context);
    lineFrameLayout.setBackgroundColor(0x26ffffff);
    passwordFrameLayout.addView(lineFrameLayout);
    layoutParams = (LayoutParams) lineFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = AndroidUtilities.dp(1);
    layoutParams.gravity = Gravity.BOTTOM | Gravity.LEFT;
    layoutParams.leftMargin = AndroidUtilities.dp(20);
    layoutParams.rightMargin = AndroidUtilities.dp(20);
    lineFrameLayout.setLayoutParams(layoutParams);

    numbersFrameLayout = new FrameLayout(context);
    addView(numbersFrameLayout);
    layoutParams = (LayoutParams) numbersFrameLayout.getLayoutParams();
    layoutParams.width = LayoutHelper.MATCH_PARENT;
    layoutParams.height = LayoutHelper.MATCH_PARENT;
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    numbersFrameLayout.setLayoutParams(layoutParams);

    lettersTextViews = new ArrayList<>(10);
    numberTextViews = new ArrayList<>(10);
    numberFrameLayouts = new ArrayList<>(10);
    for (int a = 0; a < 10; a++) {
        TextView textView = new TextView(context);
        textView.setTextColor(0xffffffff);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 36);
        textView.setGravity(Gravity.CENTER);
        textView.setText(String.format(Locale.US, "%d", a));
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(50);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        numberTextViews.add(textView);

        textView = new TextView(context);
        textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
        textView.setTextColor(0x7fffffff);
        textView.setGravity(Gravity.CENTER);
        numbersFrameLayout.addView(textView);
        layoutParams = (LayoutParams) textView.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(50);
        layoutParams.height = AndroidUtilities.dp(20);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        textView.setLayoutParams(layoutParams);
        switch (a) {
        case 0:
            textView.setText("+");
            break;
        case 2:
            textView.setText("ABC");
            break;
        case 3:
            textView.setText("DEF");
            break;
        case 4:
            textView.setText("GHI");
            break;
        case 5:
            textView.setText("JKL");
            break;
        case 6:
            textView.setText("MNO");
            break;
        case 7:
            textView.setText("PQRS");
            break;
        case 8:
            textView.setText("TUV");
            break;
        case 9:
            textView.setText("WXYZ");
            break;
        default:
            break;
        }
        lettersTextViews.add(textView);
    }
    eraseView = new ImageView(context);
    eraseView.setScaleType(ImageView.ScaleType.CENTER);
    eraseView.setImageResource(R.drawable.passcode_delete);
    numbersFrameLayout.addView(eraseView);
    layoutParams = (LayoutParams) eraseView.getLayoutParams();
    layoutParams.width = AndroidUtilities.dp(50);
    layoutParams.height = AndroidUtilities.dp(50);
    layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
    eraseView.setLayoutParams(layoutParams);
    for (int a = 0; a < 11; a++) {
        FrameLayout frameLayout = new FrameLayout(context);
        frameLayout.setBackgroundResource(R.drawable.bar_selector_lock);
        frameLayout.setTag(a);
        if (a == 10) {
            frameLayout.setOnLongClickListener(new OnLongClickListener() {
                @Override
                public boolean onLongClick(View v) {
                    passwordEditText.setText("");
                    passwordEditText2.eraseAllCharacters(true);
                    return true;
                }
            });
        }
        frameLayout.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                int tag = (Integer) v.getTag();
                switch (tag) {
                case 0:
                    passwordEditText2.appendCharacter("0");
                    break;
                case 1:
                    passwordEditText2.appendCharacter("1");
                    break;
                case 2:
                    passwordEditText2.appendCharacter("2");
                    break;
                case 3:
                    passwordEditText2.appendCharacter("3");
                    break;
                case 4:
                    passwordEditText2.appendCharacter("4");
                    break;
                case 5:
                    passwordEditText2.appendCharacter("5");
                    break;
                case 6:
                    passwordEditText2.appendCharacter("6");
                    break;
                case 7:
                    passwordEditText2.appendCharacter("7");
                    break;
                case 8:
                    passwordEditText2.appendCharacter("8");
                    break;
                case 9:
                    passwordEditText2.appendCharacter("9");
                    break;
                case 10:
                    passwordEditText2.eraseLastCharacter();
                    break;
                }
                if (passwordEditText2.lenght() == 4) {
                    processDone(false);
                }
            }
        });
        numberFrameLayouts.add(frameLayout);
    }
    for (int a = 10; a >= 0; a--) {
        FrameLayout frameLayout = numberFrameLayouts.get(a);
        numbersFrameLayout.addView(frameLayout);
        layoutParams = (LayoutParams) frameLayout.getLayoutParams();
        layoutParams.width = AndroidUtilities.dp(100);
        layoutParams.height = AndroidUtilities.dp(100);
        layoutParams.gravity = Gravity.TOP | Gravity.LEFT;
        frameLayout.setLayoutParams(layoutParams);
    }
}