Example usage for android.widget ImageView setOnClickListener

List of usage examples for android.widget ImageView setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.mobicage.rogerthat.GroupDetailActivity.java

private void updateGroupForEdit() {
    T.UI();//from  w  ww  .  j a v a2s.c  o m
    final Button saveBtn = (Button) findViewById(R.id.save_group);
    final ImageView editBtn = (ImageView) findViewById(R.id.edit_group);
    final RelativeLayout updateGroupName = ((RelativeLayout) findViewById(R.id.update_group_name));
    final LinearLayout updateGroupAvatar = ((LinearLayout) findViewById(R.id.update_group_avatar));
    final ImageView newGroupAvatar = ((ImageView) findViewById(R.id.update_group_avatar_img));
    final Button updateAvatarBtn = (Button) findViewById(R.id.update_avatar);
    final Button cancelBtn = (Button) findViewById(R.id.cancel);

    final ImageView friendAvatar = (ImageView) findViewById(R.id.friend_avatar);
    final TextView friendName = (TextView) findViewById(R.id.friend_name);

    if (mEditing) {
        updateGroupName.setVisibility(View.VISIBLE);
        updateGroupAvatar.setVisibility(View.VISIBLE);
        updateGroupName.setBackgroundResource(android.R.drawable.edit_text);
        cancelBtn.setVisibility(View.VISIBLE);
        saveBtn.setVisibility(View.VISIBLE);
        editBtn.setVisibility(View.GONE);

        friendAvatar.setVisibility(View.GONE);
        friendName.setVisibility(View.GONE);

        updateGroupName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mUpdateGroupName.requestFocus()) {
                    int pos = mUpdateGroupName.getText().length();
                    mUpdateGroupName.setSelection(pos);
                    UIUtils.showKeyboard(getApplicationContext());
                }
            }
        });

        OnClickListener newAvatarListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getNewAvatar(true);
                UIUtils.hideKeyboard(getApplicationContext(), mUpdateGroupName);
            }
        };

        updateAvatarBtn.setOnClickListener(newAvatarListener);
        newGroupAvatar.setOnClickListener(newAvatarListener);

    } else {
        updateGroupName.setVisibility(View.GONE);
        updateGroupAvatar.setVisibility(View.GONE);
        updateGroupName.setBackgroundResource(0);
        cancelBtn.setVisibility(View.GONE);
        saveBtn.setVisibility(View.GONE);
        editBtn.setVisibility(View.VISIBLE);

        friendAvatar.setVisibility(View.VISIBLE);
        friendName.setVisibility(View.VISIBLE);

        final byte[] byteArray;
        if (mPhotoSelected) {
            Bitmap bm = BitmapFactory.decodeFile(mUriSavedImage.getPath(), null);
            bm = ImageHelper.rotateBitmap(bm, mPhoneExifRotation);

            ByteArrayOutputStream stream = new ByteArrayOutputStream();
            bm.compress(Bitmap.CompressFormat.PNG, 100, stream);
            byteArray = stream.toByteArray();
            File image;
            try {
                image = getTmpUploadPhotoLocation();
            } catch (IOException e) {
                L.d(e.getMessage());
                UIUtils.showLongToast(getApplicationContext(), e.getMessage());
                return;
            }
            image.delete();
            mPhotoSelected = false;
            mGroup.avatar = byteArray;
        }
        mGroup.name = mUpdateGroupName.getText().toString();
        mFriendsPlugin.getStore().updateGroup(mGroup.guid, mGroup.name, mGroup.avatar, null);
        mFriendsPlugin.putGroup(mGroup);

        mBackupMembers = new ArrayList<String>(mGroup.members);

        Intent intent = new Intent(mIsNewGroup ? FriendsPlugin.GROUP_ADDED : FriendsPlugin.GROUP_MODIFIED);
        intent.putExtra("guid", mGroup.guid);
        mService.sendBroadcast(intent);
    }
}

From source file:com.popdeem.sdk.uikit.activity.PDUIClaimActivity.java

private void setPic(String path, int orientation) {
    ImageView mImageView = (ImageView) findViewById(R.id.pd_claim_share_image_view);

    int targetW = mImageView.getWidth();
    int targetH = mImageView.getHeight();

    mImageAdded = true;//from   ww  w.  j  a  va  2  s . c om
    image = PDUIImageUtils.getResizedBitmap(path, 500, 500, orientation);
    mImageView.setImageBitmap(image);
    twitterURI = saveBitmapToInternalCache(this, image);
    mImageView.setVisibility(View.VISIBLE);
    mImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (ContextCompat.checkSelfPermission(PDUIClaimActivity.this,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                new AlertDialog.Builder(PDUIClaimActivity.this)
                        .setTitle(getString(R.string.pd_storage_permissions_title_string))
                        .setMessage(getString(R.string.pd_storage_permission_rationale_string))
                        .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                ActivityCompat.requestPermissions(PDUIClaimActivity.this,
                                        new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 123);
                            }
                        }).setNegativeButton(android.R.string.no, null).create().show();
            } else {
                showAddPictureChoiceDialog();
            }
        }
    });
}

From source file:com.easemob.chatui.adapter.MessageAdapter.java

/**
 * load image into image view/*from   w  ww . j  a  v  a  2  s. c  om*/
 *
 * @param thumbernailPath
 * @param iv
 * @param
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                EMLog.d(TAG, "image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    EMLog.d(TAG, "here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message.getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null && message.direct == Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv,
                activity, message);
        return true;
    }

}

From source file:com.google.samples.apps.iosched.session.SessionDetailFragment.java

private void displaySpeakersData(SessionDetailModel data) {
    final ViewGroup speakersGroup = (ViewGroup) getActivity().findViewById(R.id.session_speakers_block);

    // Remove all existing speakers (everything but first child, which is the header)
    for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) {
        speakersGroup.removeViewAt(i);//from  ww w . j  ava  2  s  . c  o m
    }

    final LayoutInflater inflater = getActivity().getLayoutInflater();

    boolean hasSpeakers = false;

    List<SessionDetailModel.Speaker> speakers = data.getSpeakers();

    for (final SessionDetailModel.Speaker speaker : speakers) {

        String speakerHeader = speaker.getName();
        if (!TextUtils.isEmpty(speaker.getCompany())) {
            speakerHeader += ", " + speaker.getCompany();
        }

        final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false);
        final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header);
        final ImageView speakerImageView = (ImageView) speakerView.findViewById(R.id.speaker_image);
        final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract);
        final ImageView plusOneIcon = (ImageView) speakerView.findViewById(R.id.gplus_icon_box);
        final ImageView twitterIcon = (ImageView) speakerView.findViewById(R.id.twitter_icon_box);

        setUpSpeakerSocialIcon(speaker, twitterIcon, speaker.getTwitterUrl(), UIUtils.TWITTER_COMMON_NAME,
                UIUtils.TWITTER_PACKAGE_NAME);

        setUpSpeakerSocialIcon(speaker, plusOneIcon, speaker.getPlusoneUrl(), UIUtils.GOOGLE_PLUS_COMMON_NAME,
                UIUtils.GOOGLE_PLUS_PACKAGE_NAME);

        // A speaker may have both a Twitter and GPlus page, only a Twitter page or only a
        // GPlus page, or neither. By default, align the Twitter icon to the right and the GPlus
        // icon to its left. If only a single icon is displayed, align it to the right.
        determineSocialIconPlacement(plusOneIcon, twitterIcon);

        if (!TextUtils.isEmpty(speaker.getImageUrl()) && mSpeakersImageLoader != null) {
            mSpeakersImageLoader.loadImage(speaker.getImageUrl(), speakerImageView);
        }

        speakerHeaderView.setText(speakerHeader);
        speakerImageView.setContentDescription(getString(R.string.speaker_googleplus_profile, speakerHeader));
        UIUtils.setTextMaybeHtml(speakerAbstractView, speaker.getAbstract());

        if (!TextUtils.isEmpty(speaker.getUrl())) {
            speakerImageView.setEnabled(true);
            speakerImageView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speaker.getUrl()));
                    speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
                    UIUtils.preferPackageForIntent(getActivity(), speakerProfileIntent,
                            UIUtils.GOOGLE_PLUS_PACKAGE_NAME);
                    startActivity(speakerProfileIntent);
                }
            });
        } else {
            speakerImageView.setEnabled(false);
            speakerImageView.setOnClickListener(null);
        }

        speakersGroup.addView(speakerView);
        hasSpeakers = true;
    }

    speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE);
    updateEmptyView(data);
}

From source file:biz.bokhorst.xprivacy.ActivityMain.java

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

    final int userId = Util.getUserId(Process.myUid());

    // Check privacy service client
    if (!PrivacyService.checkClient())
        return;// w  w  w.j  a v  a 2  s. c  o m

    // Import license file
    if (Intent.ACTION_VIEW.equals(getIntent().getAction()))
        if (Util.importProLicense(new File(getIntent().getData().getPath())) != null)
            Toast.makeText(this, getString(R.string.menu_pro), Toast.LENGTH_LONG).show();

    // Set layout
    setContentView(R.layout.mainlist);
    setSupportActionBar((Toolbar) findViewById(R.id.widgetToolbar));
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // Set sub title
    if (Util.hasProLicense(this) != null)
        getSupportActionBar().setSubtitle(R.string.menu_pro);

    // Annotate
    Meta.annotate(this.getResources());

    // Get localized restriction name
    List<String> listRestrictionName = new ArrayList<String>(
            PrivacyManager.getRestrictions(this).navigableKeySet());
    listRestrictionName.add(0, getString(R.string.menu_all));

    // Build spinner adapter
    SpinnerAdapter spAdapter = new SpinnerAdapter(this, android.R.layout.simple_spinner_item);
    spAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spAdapter.addAll(listRestrictionName);

    // Handle info
    ImageView imgInfo = (ImageView) findViewById(R.id.imgInfo);
    imgInfo.setOnClickListener(new View.OnClickListener() {
        @SuppressLint("SetJavaScriptEnabled")
        @Override
        public void onClick(View view) {
            int position = spRestriction.getSelectedItemPosition();
            if (position != AdapterView.INVALID_POSITION) {
                String query = (position == 0 ? "restrictions"
                        : (String) PrivacyManager.getRestrictions(ActivityMain.this).values().toArray()[position
                                - 1]);

                WebView webview = new WebView(ActivityMain.this);
                webview.getSettings().setUserAgentString("Mozilla/5.0");
                // needed for hashtag
                webview.getSettings().setJavaScriptEnabled(true);
                webview.loadUrl("https://github.com/M66B/XPrivacy#" + query);

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this);
                alertDialogBuilder.setTitle((String) spRestriction.getSelectedItem());
                alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
                alertDialogBuilder.setView(webview);
                alertDialogBuilder.setCancelable(true);
                AlertDialog alertDialog = alertDialogBuilder.create();
                alertDialog.show();
            }
        }
    });

    // Setup category spinner
    spRestriction = (Spinner) findViewById(R.id.spRestriction);
    spRestriction.setAdapter(spAdapter);
    spRestriction.setOnItemSelectedListener(this);
    int pos = getSelectedCategory(userId);
    spRestriction.setSelection(pos);

    // Setup sort
    mSortMode = Integer.parseInt(PrivacyManager.getSetting(userId, PrivacyManager.cSettingSortMode, "0"));
    mSortInvert = PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingSortInverted, false);

    // Start task to get app list
    AppListTask appListTask = new AppListTask();
    appListTask.executeOnExecutor(mExecutor, (Object) null);

    // Check environment
    Requirements.check(this);

    // Licensing
    checkLicense();

    // Listen for package add/remove
    IntentFilter iff = new IntentFilter();
    iff.addAction(Intent.ACTION_PACKAGE_ADDED);
    iff.addAction(Intent.ACTION_PACKAGE_REMOVED);
    iff.addDataScheme("package");
    registerReceiver(mPackageChangeReceiver, iff);
    mPackageChangeReceiverRegistered = true;

    boolean showChangelog = true;

    // First run
    if (PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingFirstRun, true)) {
        showChangelog = false;
        optionAbout();
    }

    // Tutorial
    if (!PrivacyManager.getSettingBool(userId, PrivacyManager.cSettingTutorialMain, false)) {
        showChangelog = false;
        ((ScrollView) findViewById(R.id.svTutorialHeader)).setVisibility(View.VISIBLE);
        ((ScrollView) findViewById(R.id.svTutorialDetails)).setVisibility(View.VISIBLE);
    }
    View.OnClickListener listener = new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            ViewParent parent = view.getParent();
            while (!parent.getClass().equals(ScrollView.class))
                parent = parent.getParent();
            ((View) parent).setVisibility(View.GONE);
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingTutorialMain, Boolean.TRUE.toString());
        }
    };
    ((Button) findViewById(R.id.btnTutorialHeader)).setOnClickListener(listener);
    ((Button) findViewById(R.id.btnTutorialDetails)).setOnClickListener(listener);

    // Legacy
    if (!PrivacyManager.cVersion3) {
        long now = new Date().getTime();
        String legacy = PrivacyManager.getSetting(userId, PrivacyManager.cSettingLegacy, null);
        if (legacy == null || now > Long.parseLong(legacy) + 7 * 24 * 60 * 60 * 1000L) {
            showChangelog = false;
            PrivacyManager.setSetting(userId, PrivacyManager.cSettingLegacy, Long.toString(now));

            AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
            alertDialogBuilder.setTitle(R.string.app_name);
            alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher));
            alertDialogBuilder.setMessage(R.string.title_update_legacy);
            alertDialogBuilder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Util.viewUri(ActivityMain.this,
                            Uri.parse("https://github.com/M66B/XPrivacy/blob/master/CHANGELOG.md#xprivacy3"));
                }
            });
            alertDialogBuilder.setNegativeButton(android.R.string.cancel,
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            // Do nothing
                        }
                    });

            // Show dialog
            AlertDialog alertDialog = alertDialogBuilder.create();
            alertDialog.show();
        }
    }

    // Show changelog
    if (showChangelog) {
        String sVersion = PrivacyManager.getSetting(userId, PrivacyManager.cSettingChangelog, null);
        Version changelogVersion = new Version(sVersion == null ? "0.0" : sVersion);
        Version currentVersion = new Version(Util.getSelfVersionName(this));
        if (sVersion == null || changelogVersion.compareTo(currentVersion) < 0)
            optionChangelog();
    }
}

From source file:com.com.easemob.chatuidemo.adapter.MessageAdapter.java

/**
 * load image into image view//from w w  w  .j  ava  2  s .  com
 *
 * @param thumbernailPath
 * @param iv
 * @param
 * @return the image exists or not
 */
private boolean showImageView(final String thumbernailPath, final ImageView iv, final String localFullSizePath,
        String remoteDir, final EMMessage message) {
    // String imagename =
    // localFullSizePath.substring(localFullSizePath.lastIndexOf("/") + 1,
    // localFullSizePath.length());
    // final String remote = remoteDir != null ? remoteDir+imagename :
    // imagename;
    final String remote = remoteDir;
    EMLog.d("###", "local = " + localFullSizePath + " remote: " + remote);
    // first check if the thumbnail image already loaded into cache
    Bitmap bitmap = ImageCache.getInstance().get(thumbernailPath);
    if (bitmap != null) {
        // thumbnail image is already loaded, reuse the drawable
        iv.setImageBitmap(bitmap);
        iv.setClickable(true);
        iv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                EMLog.d(TAG, "image view on click");
                Intent intent = new Intent(activity, ShowBigImage.class);
                File file = new File(localFullSizePath);
                if (file.exists()) {
                    Uri uri = Uri.fromFile(file);
                    intent.putExtra("uri", uri);
                    EMLog.d(TAG, "here need to check why download everytime");
                } else {
                    // The local full size pic does not exist yet.
                    // ShowBigImage needs to download it from the server
                    // first
                    // intent.putExtra("", message.get);
                    ImageMessageBody body = (ImageMessageBody) message.getBody();
                    intent.putExtra("secret", body.getSecret());
                    intent.putExtra("remotepath", remote);
                }
                if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked
                        && message.getChatType() != ChatType.GroupChat
                        && message.getChatType() != ChatType.ChatRoom) {
                    try {
                        EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId());
                        message.isAcked = true;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
                activity.startActivity(intent);
            }
        });
        return true;
    } else {

        new LoadImageTask().execute(thumbernailPath, localFullSizePath, remote, message.getChatType(), iv,
                activity, message);
        return true;
    }

}

From source file:com.almalence.opencam.ui.AlmalenceStore.java

public void showStore() {
    LayoutInflater inflater = LayoutInflater.from(MainScreen.getInstance());
    List<RelativeLayout> pages = new ArrayList<RelativeLayout>();

    // <!-- -+-
    final boolean unlocked = false;
    //-+- -->//w  w  w . j  a  v  a 2  s.  co  m
    /* <!-- +++
    final boolean unlocked = true; 
     +++ --> */

    // page 1
    RelativeLayout page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    initStoreList();

    RelativeLayout store = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_store, null);
    final ImageView imgStoreNext = (ImageView) store.findViewById(R.id.storeWhatsNew);
    GridView gridview = (GridView) store.findViewById(R.id.storeGrid);
    gridview.setAdapter(storeAdapter);

    if (!unlocked) {
        page.addView(store);
        pages.add(page);
    }

    // page 2
    page = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_pager_fragment, null);
    RelativeLayout features = (RelativeLayout) inflater.inflate(R.layout.gui_almalence_features, null);
    final ImageView imgFeaturesPrev = (ImageView) features.findViewById(R.id.storeWhatsNew);
    imgFeaturesPrev.setVisibility(View.INVISIBLE);
    WebView wv = (WebView) features.findViewById(R.id.text_features);
    wv.loadUrl("file:///android_asset/www/features.html");

    page.addView(features);
    pages.add(page);

    SamplePagerAdapter pagerAdapter = new SamplePagerAdapter(pages);
    final ViewPager viewPager = new ViewPager(MainScreen.getInstance());
    viewPager.setAdapter(pagerAdapter);
    if (!unlocked)
        viewPager.setCurrentItem(0);
    else
        viewPager.setCurrentItem(1);
    viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener() {
        @Override
        public void onPageSelected(int position) {
            switch (position) {
            case 0:
                // 0
                imgStoreNext.setVisibility(View.VISIBLE);
                // 1
                imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            case 1:
                // 0
                imgStoreNext.setVisibility(View.INVISIBLE);
                // 1
                if (!unlocked)
                    imgFeaturesPrev.setVisibility(View.VISIBLE);
                else
                    imgFeaturesPrev.setVisibility(View.INVISIBLE);
                break;
            default:
                break;
            }
        }
    });

    imgStoreNext.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });

    imgFeaturesPrev.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });

    guiView.findViewById(R.id.buttonGallery).setEnabled(false);
    guiView.findViewById(R.id.buttonShutter).setEnabled(false);
    guiView.findViewById(R.id.buttonSelectMode).setEnabled(false);

    PluginManager.getInstance().sendMessage(ApplicationInterface.MSG_BROADCAST,
            ApplicationInterface.MSG_CONTROL_LOCKED);

    MainScreen.getGUIManager().lockControls = true;

    // <!-- -+-
    if (MainScreen.getInstance().showPromoRedeemed) {
        Toast.makeText(MainScreen.getInstance(),
                "The promo code has been successfully redeemed. All PRO-Features are unlocked",
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemed = false;
    }
    if (MainScreen.getInstance().showPromoRedeemedJulius) {
        Toast.makeText(MainScreen.getInstance(),
                MainScreen.getInstance().getResources().getString(R.string.promoRedeemedJulius),
                Toast.LENGTH_LONG).show();
        MainScreen.getInstance().showPromoRedeemedJulius = false;
    }
    //-+- -->

    final RelativeLayout pagerLayout = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayout));
    pagerLayout.addView(viewPager);

    final RelativeLayout pagerLayoutMain = ((RelativeLayout) guiView.findViewById(R.id.viewPagerLayoutMain));
    pagerLayoutMain.setVisibility(View.VISIBLE);
    pagerLayoutMain.bringToFront();

    // We need this timer, to show store on top, after we return from google
    // play.
    // In MainScreen there is timer, which brings main buttons on top,
    // after MainScreen activity resumed.
    // So this timer "blocks" timer from MainScreen if we want to show
    // store.
    new CountDownTimer(600, 10) {
        public void onTick(long millisUntilFinished) {
            pagerLayoutMain.bringToFront();
        }

        public void onFinish() {
            pagerLayoutMain.bringToFront();
        }
    }.start();
}

From source file:com.asksven.betterbatterystats.adapters.StatsAdapter.java

public View getView(int position, View convertView, ViewGroup viewGroup) {
    StatElement entry = m_listData.get(position);

    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this.m_context);
    boolean bShowBars = sharedPrefs.getBoolean("show_gauge", false);

    if (LogSettings.DEBUG) {
        Log.i(TAG, "Values: " + entry.getVals());
    }//from  ww  w .  j a  va  2 s  . c om

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) m_context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        // depending on settings show new pie gauge or old bar gauge
        if (!bShowBars) {
            convertView = inflater.inflate(R.layout.stat_row, null);
        } else {
            convertView = inflater.inflate(R.layout.stat_row_gauge, null);
        }
    }

    final float scale = this.m_context.getResources().getDisplayMetrics().density;

    TextView tvName = (TextView) convertView.findViewById(R.id.TextViewName);

    /////////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String fontSize = sharedPrefs.getString("medium_font_size", "16");
    int mediumFontSize = Integer.parseInt(fontSize);

    //we need to change "since" fontsize
    tvName.setTextSize(TypedValue.COMPLEX_UNIT_SP, mediumFontSize);

    // We need to handle an exception here: Sensors do not have a name so we use the fqn instead
    if (entry instanceof SensorUsage) {
        tvName.setText(entry.getFqn(UidNameResolver.getInstance(m_context)));

    } else {
        tvName.setText(entry.getName());
    }

    boolean bShowKb = sharedPrefs.getBoolean("enable_kb", true);
    ImageView iconKb = (ImageView) convertView.findViewById(R.id.imageKB);

    iconKb.setVisibility(View.INVISIBLE);

    TextView tvFqn = (TextView) convertView.findViewById(R.id.TextViewFqn);
    tvFqn.setText(entry.getFqn(UidNameResolver.getInstance(m_context)));

    TextView tvData = (TextView) convertView.findViewById(R.id.TextViewData);

    // for alarms the values is wakeups per hour so we need to take the time as reference for the text
    if (entry instanceof Alarm) {
        tvData.setText(entry.getData((long) m_timeSince));
    } else {
        tvData.setText(entry.getData((long) m_maxValue));
    }

    //LinearLayout myLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutBar);
    LinearLayout myFqnLayout = (LinearLayout) convertView.findViewById(R.id.LinearLayoutFqn);
    LinearLayout myRow = (LinearLayout) convertView.findViewById(R.id.LinearLayoutEntry);

    // long press for "copy to clipboard"
    convertView.setOnLongClickListener(new OnItemLongClickListener(position));

    if (!bShowBars) {
        GraphablePie gauge = (GraphablePie) convertView.findViewById(R.id.Gauge);

        /////////////////////////////////////////
        // we do some stuff here to handle settings about font size and thumbnail size
        String iconDim = sharedPrefs.getString("thumbnail_size", "56");
        int iconSize = Integer.parseInt(iconDim);
        int pixels = (int) (iconSize * scale + 0.5f);
        //we need to change "since" fontsize
        gauge.getLayoutParams().height = pixels;
        gauge.getLayoutParams().width = pixels;
        gauge.requestLayout();

        ////////////////////////////////////////////////////////////////////////////////////
        if (entry instanceof NetworkUsage) {
            gauge.setValue(entry.getValues()[0], ((NetworkUsage) entry).getTotal());

        } else {
            double max = m_maxValue;
            // avoid rounding errors leading to values > 100 %
            if (entry.getValues()[0] > max) {
                max = entry.getValues()[0];
                Log.i(TAG, "Upping gauge max to " + max);
            }
            gauge.setValue(entry.getValues()[0], max);
        }
    } else {
        GraphableBars buttonBar = (GraphableBars) convertView.findViewById(R.id.ButtonBar);
        int iHeight = 10;
        try {
            iHeight = Integer.valueOf(sharedPrefs.getString("graph_bar_height", "10"));
        } catch (Exception e) {
            iHeight = 10;
        }
        if (iHeight == 0) {
            iHeight = 10;
        }

        buttonBar.setMinimumHeight(iHeight);
        buttonBar.setName(entry.getName());
        buttonBar.setValues(entry.getValues(), m_maxValue);
    }
    ImageView iconView = (ImageView) convertView.findViewById(R.id.icon);
    LinearLayout iconLayout = (LinearLayout) convertView.findViewById(R.id.LayoutIcon);
    /////////////////////////////////////////
    // we do some stuff here to handle settings about font size and thumbnail size
    String iconDim = sharedPrefs.getString("thumbnail_size", "56");
    int iconSize = Integer.parseInt(iconDim);
    int pixels = (int) (iconSize * scale + 0.5f);
    //we need to change "since" fontsize
    iconView.getLayoutParams().width = pixels;
    iconView.getLayoutParams().height = pixels;
    iconView.requestLayout();
    //n 20;setLay.setTextSize(TypedValue.COMPLEX_UNIT_DIP, iconSize);

    ////////////////////////////////////////////////////////////////////////////////////

    // add on click listener for the icon only if KB is enabled
    //        if (bShowKb)
    //        {
    //           // set a click listener for the list
    //           iconKb.setOnClickListener(new OnIconClickListener(position));
    //        }

    // show / hide fqn text
    if ((entry instanceof Process) || (entry instanceof State) || (entry instanceof Misc)
            || (entry instanceof NativeKernelWakelock) || (entry instanceof Alarm)
            || (entry instanceof SensorUsage)) {
        myFqnLayout.setVisibility(View.GONE);
    } else {
        myFqnLayout.setVisibility(View.VISIBLE);
    }

    // show / hide package icons (we show / hide the whole layout as it contains a margin that must be hidded as well
    if ((entry instanceof NativeKernelWakelock) || (entry instanceof State) || (entry instanceof Misc)) {

        iconView.setVisibility(View.GONE);

    } else {
        iconView.setVisibility(View.VISIBLE);
        iconView.setImageDrawable(entry.getIcon(UidNameResolver.getInstance(m_context)));
        // set a click listener for the list
        iconView.setOnClickListener(new OnPackageClickListener(position));

    }

    // add on click listener for the list entry if details are availble
    if ((entry instanceof Alarm) || (entry instanceof NativeKernelWakelock) || (entry instanceof SensorUsage)) {
        convertView.setOnClickListener(new OnItemClickListener(position));
    }

    //        // show / hide set dividers
    //        ListView myList = (ListView) convertView.getListView(); //findViewById(R.id.id.list);
    //        myList.setDivider(new ColorDrawable(0x99F10529));
    //        myList.setDividerHeight(1);
    return convertView;
}

From source file:com.owncloud.android.ui.adapter.FileListListAdapter.java

@Override
public View getView(final int position, View convertView, ViewGroup parent) {
    View view = convertView;/*from w w  w  .j  av  a 2 s. c  o m*/
    if (view == null) {
        LayoutInflater inflator = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflator.inflate(R.layout.list_item, null);
    }

    if (mFiles != null && mFiles.size() > position) {
        OCFile file = mFiles.get(position);
        TextView fileName = (TextView) view.findViewById(R.id.Filename);
        String name = file.getFileName();
        if (dataSourceShareFile == null)
            dataSourceShareFile = new DbShareFile(mContext);

        Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
        String[] accountNames = account.name.split("@");

        if (accountNames.length > 2) {
            accountName = accountNames[0] + "@" + accountNames[1];
            url = accountNames[2];
        }
        Map<String, String> fileSharers = dataSourceShareFile.getUsersWhoSharedFilesWithMe(accountName);
        TextView sharer = (TextView) view.findViewById(R.id.sharer);
        ImageView shareButton = (ImageView) view.findViewById(R.id.shareItem);
        fileName.setText(name);
        ImageView fileIcon = (ImageView) view.findViewById(R.id.imageView1);
        fileIcon.setImageResource(DisplayUtils.getResourceId(file.getMimetype()));
        ImageView localStateView = (ImageView) view.findViewById(R.id.imageView2);
        FileDownloaderBinder downloaderBinder = mTransferServiceGetter.getFileDownloaderBinder();
        FileUploaderBinder uploaderBinder = mTransferServiceGetter.getFileUploaderBinder();
        if (fileSharers.size() != 0 && (!file.equals("Shared") && file.getRemotePath().contains("Shared"))) {
            if (fileSharers.containsKey(name)) {
                sharer.setText(fileSharers.get(name));
                fileSharers.remove(name);
            } else {
                sharer.setText(" ");
            }
        } else {
            sharer.setText(" ");
        }

        if (downloaderBinder != null && downloaderBinder.isDownloading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.downloading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (uploaderBinder != null && uploaderBinder.isUploading(mAccount, file)) {
            localStateView.setImageResource(R.drawable.uploading_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else if (file.isDown()) {
            localStateView.setImageResource(R.drawable.local_file_indicator);
            localStateView.setVisibility(View.VISIBLE);
        } else {
            localStateView.setVisibility(View.INVISIBLE);
        }

        TextView fileSizeV = (TextView) view.findViewById(R.id.file_size);
        TextView lastModV = (TextView) view.findViewById(R.id.last_mod);
        ImageView checkBoxV = (ImageView) view.findViewById(R.id.custom_checkbox);
        shareButton.setOnClickListener(new OnClickListener() {
            String shareStatusDisplay;
            int flagShare = 0;

            @Override
            public void onClick(View v) {
                final Dialog dialog = new Dialog(mContext);
                final OCFile fileToBeShared = (OCFile) getItem(position);
                final ArrayAdapter<String> shareWithFriends;
                final ArrayAdapter<String> shareAdapter;
                final String filePath;
                sharedWith = new ArrayList<String>();
                dataSource = new DbFriends(mContext);
                dataSourceShareFile = new DbShareFile(mContext);
                dialog.setContentView(R.layout.share_file_with);
                dialog.setTitle("Share");
                Account account = AccountUtils.getCurrentOwnCloudAccount(mContext);
                String[] accountNames = account.name.split("@");

                if (accountNames.length > 2) {
                    accountName = accountNames[0] + "@" + accountNames[1];
                    url = accountNames[2];
                }

                final AutoCompleteTextView textView = (AutoCompleteTextView) dialog
                        .findViewById(R.id.autocompleteshare);
                Button shareBtn = (Button) dialog.findViewById(R.id.ShareBtn);
                Button doneBtn = (Button) dialog.findViewById(R.id.ShareDoneBtn);
                final ListView listview = (ListView) dialog.findViewById(R.id.alreadySharedWithList);

                textView.setThreshold(2);
                final String itemType;

                filePath = "files" + String.valueOf(fileToBeShared.getRemotePath());
                final String fileName = fileToBeShared.getFileName();
                final String fileRemotePath = fileToBeShared.getRemotePath();
                if (dataSourceShareFile == null)
                    dataSourceShareFile = new DbShareFile(mContext);
                sharedWith = dataSourceShareFile.getUsersWithWhomIhaveSharedFile(fileName, fileRemotePath,
                        accountName, String.valueOf(1));
                shareAdapter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        sharedWith);
                listview.setAdapter(shareAdapter);
                final String itemSource;
                if (fileToBeShared.isDirectory()) {
                    itemType = "folder";
                    int lastSlashInFolderPath = filePath.lastIndexOf('/');
                    itemSource = filePath.substring(0, lastSlashInFolderPath);
                } else {
                    itemType = "file";
                    itemSource = filePath;
                }

                //Permissions disabled with friends app
                ArrayList<String> friendList = dataSource.getFriendList(accountName);
                dataSource.close();
                shareWithFriends = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_1,
                        friendList);
                textView.setAdapter(shareWithFriends);
                textView.setFocusableInTouchMode(true);
                dialog.show();
                textView.setOnItemClickListener(new OnItemClickListener() {

                    @Override
                    public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

                    }
                });
                final Handler finishedHandler = new Handler() {
                    @Override
                    public void handleMessage(Message msg) {
                        shareAdapter.notifyDataSetChanged();
                        Toast.makeText(mContext, shareStatusDisplay, Toast.LENGTH_SHORT).show();

                    }
                };
                shareBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        final String shareWith = textView.getText().toString();

                        if (shareWith.equals("")) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext,
                                    "Please enter the friends name with whom you want to share",
                                    Toast.LENGTH_SHORT).show();
                        } else if (sharedWith.contains(shareWith)) {
                            textView.setHint("Share With");
                            Toast.makeText(mContext, "You have shared the file with that person",
                                    Toast.LENGTH_SHORT).show();
                        } else {

                            textView.setText("");
                            Runnable runnable = new Runnable() {
                                @Override
                                public void run() {
                                    HttpPost post = new HttpPost(
                                            "http://" + url + "/owncloud/androidshare.php");
                                    final ArrayList<NameValuePair> params = new ArrayList<NameValuePair>();

                                    params.add(new BasicNameValuePair("itemType", itemType));
                                    params.add(new BasicNameValuePair("itemSource", itemSource));
                                    params.add(new BasicNameValuePair("shareType", shareType));
                                    params.add(new BasicNameValuePair("shareWith", shareWith));
                                    params.add(new BasicNameValuePair("permission", permissions));
                                    params.add(new BasicNameValuePair("uidOwner", accountName));
                                    HttpEntity entity;
                                    String shareSuccess = "false";
                                    try {
                                        entity = new UrlEncodedFormEntity(params, "utf-8");
                                        HttpClient client = new DefaultHttpClient();
                                        post.setEntity(entity);
                                        HttpResponse response = client.execute(post);

                                        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
                                            HttpEntity entityresponse = response.getEntity();
                                            String jsonentity = EntityUtils.toString(entityresponse);
                                            JSONObject obj = new JSONObject(jsonentity);
                                            shareSuccess = obj.getString("SHARE_STATUS");
                                            flagShare = 1;
                                            if (shareSuccess.equals("true")) {
                                                dataSourceShareFile.putNewShares(fileName, fileRemotePath,
                                                        accountName, shareWith);
                                                sharedWith.add(shareWith);
                                                shareStatusDisplay = "File share succeeded";
                                            } else if (shareSuccess.equals("INVALID_FILE")) {
                                                shareStatusDisplay = "File you are trying to share does not exist";
                                            } else if (shareSuccess.equals("INVALID_SHARETYPE")) {
                                                shareStatusDisplay = "File Share type is invalid";
                                            } else {
                                                shareStatusDisplay = "Share did not succeed. Please check your internet connection";
                                            }

                                            finishedHandler.sendEmptyMessage(flagShare);

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

                                }
                            };
                            new Thread(runnable).start();

                        }

                        if (flagShare == 1) {
                        }

                    }

                });
                doneBtn.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        dialog.dismiss();
                        //dataSourceShareFile.close();
                    }
                });
            }

        });
        //dataSourceShareFile.close();
        if (!file.isDirectory()) {
            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            // this if-else is needed even thoe fav icon is visible by default
            // because android reuses views in listview
            if (!file.keepInSync()) {
                view.findViewById(R.id.imageView3).setVisibility(View.GONE);
            } else {
                view.findViewById(R.id.imageView3).setVisibility(View.VISIBLE);
            }

            ListView parentList = (ListView) parent;
            if (parentList.getChoiceMode() == ListView.CHOICE_MODE_NONE) {
                checkBoxV.setVisibility(View.GONE);
            } else {
                if (parentList.isItemChecked(position)) {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_on_background);
                } else {
                    checkBoxV.setImageResource(android.R.drawable.checkbox_off_background);
                }
                checkBoxV.setVisibility(View.VISIBLE);
            }

        } else {

            fileSizeV.setVisibility(View.VISIBLE);
            fileSizeV.setText(DisplayUtils.bytesToHumanReadable(file.getFileLength()));
            lastModV.setVisibility(View.VISIBLE);
            lastModV.setText(DisplayUtils.unixTimeToHumanReadable(file.getModificationTimestamp()));
            checkBoxV.setVisibility(View.GONE);
            view.findViewById(R.id.imageView3).setVisibility(View.GONE);
        }
    }

    return view;
}

From source file:com.lifehackinnovations.siteaudit.FloorPlanActivity.java

public void getscaledialog() {

    ImageView googlemaps = new ImageView(this);
    googlemaps.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    googlemaps.setPadding(25, 25, 25, 25);
    googlemaps.setImageResource(R.drawable.google_maps256x256);
    googlemaps.setOnClickListener(new ImageView.OnClickListener() {
        public void onClick(View v) {

            startActivity(u.intent("Getscalefromgooglemaps"));
            getscaledialog.cancel();//from  w  w w. j  a v  a  2  s.c  o m

        }
    });

    ImageView twopoints = new ImageView(this);
    twopoints.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    twopoints.setPadding(25, 25, 25, 25);
    twopoints.setImageResource(R.drawable.pointsonmapicon);
    twopoints.setOnClickListener(new ImageView.OnClickListener() {

        public void onClick(View v) {

            ACTION = ACTION_GETSCALEFROMPOINTS;
            toptoolbar.setVisibility(View.INVISIBLE);
            righttoolbar.setVisibility(View.INVISIBLE);

            floorplantitle.setVisibility(View.VISIBLE);
            floorplantitle.setText("Please select first point");

            GETSCALESTAGE = STAGE_GETFIRSTPOINT;

            getscaledialog.cancel();

        }

    });

    LinearLayout choosepicturelocationlayout;
    choosepicturelocationlayout = new LinearLayout(this);
    choosepicturelocationlayout
            .setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
    choosepicturelocationlayout.setOrientation(LinearLayout.HORIZONTAL);
    choosepicturelocationlayout.addView(googlemaps);
    choosepicturelocationlayout.addView(twopoints);
    choosepicturelocationlayout.setGravity(Gravity.CENTER_HORIZONTAL);

    AlertDialog.Builder builder = new AlertDialog.Builder(this);
    builder.setTitle("Choose Method for Getting Scale")
            .setMessage("Please choose Google Maps, or Two Points on Map").setView(choosepicturelocationlayout)
            .setCancelable(false).setIcon(R.drawable.ic_launcher)

            .setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            }).setCancelable(true);

    getscaledialog = builder.create();
    getscaledialog.show();

}