Example usage for android.view View getLocationOnScreen

List of usage examples for android.view View getLocationOnScreen

Introduction

In this page you can find the example usage for android.view View getLocationOnScreen.

Prototype

public void getLocationOnScreen(@Size(2) int[] outLocation) 

Source Link

Document

Computes the coordinates of this view on the screen.

Usage

From source file:com.javielinux.utils.PopupLinks.java

public void showLinks(View view, InfoTweet infoTweet) {

    ArrayList<String> linksInText = LinksUtils.pullLinks(infoTweet.getText(), infoTweet.getContentURLs());
    selectedInfoTweet = infoTweet;//  w  ww.  ja  v  a2 s .  c om

    if (linksInText.size() == 1) {
        goToLink(linksInText.get(0));
    } else {

        int widthContainer = widthScreen;
        int heightContainer = heightScreen;

        links.clear();
        links.addAll(linksInText);

        int rows = 0;

        if (links.size() > 4) {
            rows = links.size() / 3;
            if (links.size() % 3 > 0)
                rows++;
            gvLinks.setNumColumns(3);
            widthContainer = (widthScreen / 4) * 3 + Utils.dip2px(activity, 40);
        } else {
            rows = links.size() / 2;
            if (links.size() % 2 > 0)
                rows++;
            gvLinks.setNumColumns(2);
            widthContainer = (widthScreen / 4) * 2 + Utils.dip2px(activity, 30);
        }
        if (rows == 1) {
            heightContainer = Utils.dip2px(activity, 110);
        } else {
            heightContainer = Utils.dip2px(activity, 100) * rows;
        }

        linksAdapter.notifyDataSetChanged();

        if (statusBarHeight <= 0) {
            Rect rect = new Rect();
            activity.getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
            statusBarHeight = rect.top;
        }
        int[] loc = new int[2];
        view.getLocationOnScreen(loc);

        int widthView = view.getMeasuredWidth();
        int heightView = view.getMeasuredHeight();

        int x = loc[0] + (widthView / 2) - (widthContainer / 2);
        int y = loc[1] - statusBarHeight + (heightView / 2) - (heightContainer / 2);

        int xCenterView = loc[0] + (widthView / 2);
        int yCenterView = loc[1] - statusBarHeight + (heightView / 2);

        int top = (int) activity.getResources().getDimension(R.dimen.actionbar_height);
        int bottom = heightScreen - statusBarHeight;

        if (x < 0)
            x = 0;
        if (y < top)
            y = top;
        if (x > widthScreen - widthContainer)
            x = widthScreen - widthContainer;
        if (y > bottom - heightContainer)
            y = bottom - heightContainer;

        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(x, y, 0, 0);
        layoutLinks.setLayoutParams(params);

        layoutMainLinks.setVisibility(View.VISIBLE);

        ObjectAnimator translationX = ObjectAnimator.ofFloat(layoutLinks, "translationX", xCenterView - x, 0f);
        translationX.setDuration(150);
        ObjectAnimator scaleX = ObjectAnimator.ofFloat(layoutLinks, "scaleX", 0f, 1f);
        scaleX.setDuration(150);
        ObjectAnimator scaleY = ObjectAnimator.ofFloat(layoutLinks, "scaleY", 0f, 1f);
        scaleY.setDuration(150);
        ObjectAnimator fadeAnim = ObjectAnimator.ofFloat(layoutLinks, "alpha", 0f, 1f);
        fadeAnim.setDuration(150);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(translationX, scaleX, scaleY, fadeAnim);
        animatorSet.start();
    }
}

From source file:com.android.mail.ui.ConversationViewFragment.java

private void focusAndScrollToView(View v) {
    // Make sure that v is in view
    final int[] coords = new int[2];
    v.getLocationOnScreen(coords);
    final int bottom = coords[1] + v.getHeight();
    if (bottom > mMaxScreenHeight) {
        mWebView.scrollBy(0, bottom - mMaxScreenHeight);
    } else if (coords[1] < mTopOfVisibleScreen) {
        mWebView.scrollBy(0, coords[1] - mTopOfVisibleScreen);
    }/*from w w w.j a v  a 2 s  .  c o m*/
    v.requestFocus();
}

From source file:eu.faircode.adblocker.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());/* www  . ja  v a 2 s  .  c  om*/

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    swEnabled = (SwitchCompat) findViewById(R.id.swEnabled);
    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);

    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.START, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    //        RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    //        rvApplication.setHasFixedSize(true);
    //        rvApplication.setLayoutManager(new LinearLayoutManager(this));
    //        adapter = new AdapterRule(this);
    //        rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    //        swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    //        swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    //        swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    //        swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
    //            @Override
    //            public void onRefresh() {
    //                Rule.clearCache(ActivityMain.this);
    //                ServiceSinkhole.reload("pull", ActivityMain.this);
    //                updateApplicationList(null);
    //            }
    //        });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

From source file:com.taobao.weex.devtools.inspector.protocol.module.DOM.java

@ChromeDevtoolsMethod
public GetBoxModelResponse getBoxModel(JsonRpcPeer peer, JSONObject params) {
    GetBoxModelResponse response = new GetBoxModelResponse();
    final BoxModel model = new BoxModel();
    final GetBoxModelRequest request = mObjectMapper.convertValue(params, GetBoxModelRequest.class);

    if (request.nodeId == null) {
        return null;
    }/* ww  w . jav  a2 s  .c  o m*/

    response.model = model;

    mDocument.postAndWait(new Runnable() {
        @Override
        public void run() {
            final Object elementForNodeId = mDocument.getElementForNodeId(request.nodeId);

            if (elementForNodeId == null) {
                LogUtil.w("Failed to get style of an element that does not exist, nodeid=" + request.nodeId);
                return;
            }

            mDocument.getElementStyles(elementForNodeId, new StyleAccumulator() {
                @Override
                public void store(String name, String value, boolean isDefault) {
                    double left = 0;
                    double right = 0;
                    double top = 0;
                    double bottom = 0;

                    double paddingLeft = 0;
                    double paddingRight = 0;
                    double paddingTop = 0;
                    double paddingBottom = 0;

                    double marginLeft = 0;
                    double marginRight = 0;
                    double marginTop = 0;
                    double marginBottom = 0;

                    double borderLeftWidth = 0;
                    double borderRightWidth = 0;
                    double borderTopWidth = 0;
                    double borderBottomWidth = 0;

                    View view = null;
                    if (isNativeMode()) {
                        if (elementForNodeId instanceof View) {
                            view = (View) elementForNodeId;
                        }
                    } else {
                        if (elementForNodeId instanceof WXComponent) {
                            view = ((WXComponent) elementForNodeId).getHostView();
                        }
                    }

                    if (view != null && view.isShown()) {
                        float scale = ScreencastDispatcher.getsBitmapScale();
                        model.width = view.getWidth();
                        model.height = view.getHeight();
                        if (!DOM.isNativeMode()) {
                            model.width = (int) (model.width * 750 / WXViewUtils.getScreenWidth() + 0.5);
                            model.height = (int) (model.height * 750 / WXViewUtils.getScreenWidth() + 0.5);
                        }

                        int[] location = new int[2];
                        view.getLocationOnScreen(location);

                        left = location[0] * scale;
                        top = location[1] * scale;
                        right = left + view.getWidth() * scale;
                        bottom = top + view.getHeight() * scale;

                        paddingLeft = view.getPaddingLeft() * scale;
                        paddingTop = view.getPaddingTop() * scale;
                        paddingRight = view.getPaddingRight() * scale;
                        paddingBottom = view.getPaddingBottom() * scale;

                        if (view instanceof ViewGroup) {
                            ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
                            if (layoutParams != null) {
                                if (layoutParams instanceof ViewGroup.MarginLayoutParams) {
                                    ViewGroup.MarginLayoutParams margins = (ViewGroup.MarginLayoutParams) layoutParams;
                                    marginLeft = margins.leftMargin * scale;
                                    marginTop = margins.topMargin * scale;
                                    marginRight = margins.rightMargin * scale;
                                    marginBottom = margins.bottomMargin * scale;
                                }
                            }
                        }
                    }
                    ArrayList<Double> padding = new ArrayList<>(8);
                    padding.add(left + borderLeftWidth);
                    padding.add(top + borderTopWidth);
                    padding.add(right - borderRightWidth);
                    padding.add(top + borderTopWidth);
                    padding.add(right - borderRightWidth);
                    padding.add(bottom - borderBottomWidth);
                    padding.add(left + borderLeftWidth);
                    padding.add(bottom - borderBottomWidth);
                    model.padding = padding;

                    ArrayList<Double> content = new ArrayList<>(8);
                    content.add(left + borderLeftWidth + paddingLeft);
                    content.add(top + borderTopWidth + paddingTop);
                    content.add(right - borderRightWidth - paddingRight);
                    content.add(top + borderTopWidth + paddingTop);
                    content.add(right - borderRightWidth - paddingRight);
                    content.add(bottom - borderBottomWidth - paddingBottom);
                    content.add(left + borderLeftWidth + paddingLeft);
                    content.add(bottom - borderBottomWidth - paddingBottom);
                    model.content = content;

                    ArrayList<Double> border = new ArrayList<>(8);
                    border.add(left);
                    border.add(top);
                    border.add(right);
                    border.add(top);
                    border.add(right);
                    border.add(bottom);
                    border.add(left);
                    border.add(bottom);
                    model.border = border;

                    ArrayList<Double> margin = new ArrayList<>(8);
                    margin.add(left - marginLeft);
                    margin.add(top - marginTop);
                    margin.add(right + marginRight);
                    margin.add(top - marginTop);
                    margin.add(right + marginRight);
                    margin.add(bottom + marginBottom);
                    margin.add(left - marginLeft);
                    margin.add(bottom + marginBottom);
                    model.margin = margin;
                }
            });
        }
    });

    return response;
}

From source file:org.mariotaku.twidere.fragment.support.UserFragment.java

@Override
public void onActivityCreated(final Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    final FragmentActivity activity = getActivity();
    setHasOptionsMenu(true);//  w ww .ja va  2 s  .c om
    getSharedPreferences(USER_COLOR_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    getSharedPreferences(USER_NICKNAME_PREFERENCES_NAME, Context.MODE_PRIVATE)
            .registerOnSharedPreferenceChangeListener(this);
    mUserColorNameManager = UserColorNameManager.getInstance(activity);
    mPreferences = SharedPreferencesWrapper.getInstance(activity, SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE,
            SharedPreferenceConstants.class);
    mNameFirst = mPreferences.getBoolean(KEY_NAME_FIRST);
    mLocale = getResources().getConfiguration().locale;
    mCardBackgroundColor = ThemeUtils.getCardBackgroundColor(activity,
            ThemeUtils.getThemeBackgroundOption(activity), ThemeUtils.getUserThemeBackgroundAlpha(activity));
    mActionBarShadowColor = 0xA0000000;
    final TwidereApplication app = TwidereApplication.getInstance(activity);
    mProfileImageLoader = app.getMediaLoaderWrapper();
    final Bundle args = getArguments();
    long accountId = -1, userId = -1;
    String screenName = null;
    if (savedInstanceState != null) {
        args.putAll(savedInstanceState);
    } else {
        accountId = args.getLong(EXTRA_ACCOUNT_ID, -1);
        userId = args.getLong(EXTRA_USER_ID, -1);
        screenName = args.getString(EXTRA_SCREEN_NAME);
    }

    Utils.setNdefPushMessageCallback(activity, new CreateNdefMessageCallback() {

        @Override
        public NdefMessage createNdefMessage(NfcEvent event) {
            final ParcelableUser user = getUser();
            if (user == null)
                return null;
            return new NdefMessage(new NdefRecord[] {
                    NdefRecord.createUri(LinkCreator.getTwitterUserLink(user.screen_name)), });
        }
    });

    activity.setEnterSharedElementCallback(new SharedElementCallback() {

        @Override
        public void onSharedElementStart(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            final int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionSource(bounds);
            }
            super.onSharedElementStart(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

        @Override
        public void onSharedElementEnd(List<String> sharedElementNames, List<View> sharedElements,
                List<View> sharedElementSnapshots) {
            int idx = sharedElementNames.indexOf(TRANSITION_NAME_PROFILE_IMAGE);
            if (idx != -1) {
                final View view = sharedElements.get(idx);
                int[] location = new int[2];
                final RectF bounds = new RectF(0, 0, view.getWidth(), view.getHeight());
                view.getLocationOnScreen(location);
                bounds.offsetTo(location[0], location[1]);
                mProfileImageView.setTransitionDestination(bounds);
            }
            super.onSharedElementEnd(sharedElementNames, sharedElements, sharedElementSnapshots);
        }

    });

    ViewCompat.setTransitionName(mProfileImageView, TRANSITION_NAME_PROFILE_IMAGE);
    ViewCompat.setTransitionName(mProfileTypeView, TRANSITION_NAME_PROFILE_TYPE);
    //        ViewCompat.setTransitionName(mCardView, TRANSITION_NAME_CARD);

    mHeaderDrawerLayout.setDrawerCallback(this);

    mPagerAdapter = new SupportTabsAdapter(activity, getChildFragmentManager());

    mViewPager.setOffscreenPageLimit(3);
    mViewPager.setAdapter(mPagerAdapter);
    mPagerIndicator.setViewPager(mViewPager);
    mPagerIndicator.setTabDisplayOption(TabPagerIndicator.LABEL);
    mPagerIndicator.setOnPageChangeListener(this);

    mFollowButton.setOnClickListener(this);
    mProfileImageView.setOnClickListener(this);
    mProfileBannerView.setOnClickListener(this);
    mListedContainer.setOnClickListener(this);
    mFollowersContainer.setOnClickListener(this);
    mFriendsContainer.setOnClickListener(this);
    mHeaderErrorIcon.setOnClickListener(this);
    mProfileBannerView.setOnSizeChangedListener(this);
    mProfileBannerSpace.setOnTouchListener(this);

    mProfileNameBackground.setBackgroundColor(mCardBackgroundColor);
    mProfileDetailsContainer.setBackgroundColor(mCardBackgroundColor);
    mPagerIndicator.setBackgroundColor(mCardBackgroundColor);
    mUuckyFooter.setBackgroundColor(mCardBackgroundColor);

    final float actionBarElevation = ThemeUtils.getSupportActionBarElevation(activity);
    ViewCompat.setElevation(mPagerIndicator, actionBarElevation);

    if (activity instanceof IThemedActivity) {
        ViewSupport.setBackground(mPagerOverlay, ThemeUtils.getNormalWindowContentOverlay(activity,
                ((IThemedActivity) activity).getCurrentThemeResourceId()));
        ViewSupport.setBackground(mErrorOverlay, ThemeUtils.getNormalWindowContentOverlay(activity,
                ((IThemedActivity) activity).getCurrentThemeResourceId()));
    }

    setupBaseActionBar();
    setupUserPages();
    if (activity instanceof IThemedActivity) {
        setUiColor(((IThemedActivity) activity).getCurrentThemeColor());
    }

    getUserInfo(accountId, userId, screenName, false);
}

From source file:com.master.metehan.filtereagle.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());/*from w  w w  . j a  va2  s.c  om*/

    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }

    Util.setTheme(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    running = true;

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    boolean enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);
    SharedPreferences.Editor editor = prefs.edit();
    editor.putBoolean("registered", true).commit();
    editor.putBoolean("logged", false).commit();
    prefs.edit().remove("hint_system").apply();

    // Register app
    String key = this.getString(R.string.app_key);
    String server_url = this.getString(R.string.serverurl);
    Register register = new Register(server_url, key, getApplicationContext());
    register.registerApp();

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);
    swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    swEnabled.setChecked(enabled);
    swEnabled.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                // com.android.vpndialogs.ConfirmDialog required
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);

    // Application list
    RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    rvApplication.setHasFixedSize(true);
    rvApplication.setLayoutManager(new LinearLayoutManager(this));
    adapter = new AdapterRule(this);
    rvApplication.setAdapter(adapter);

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Rule.clearCache(ActivityMain.this);
            ServiceSinkhole.reload("pull", ActivityMain.this);
            updateApplicationList(null);
        }
    });

    final LinearLayout llSystem = (LinearLayout) findViewById(R.id.llSystem);
    Button btnSystem = (Button) findViewById(R.id.btnSystem);
    boolean system = prefs.getBoolean("manage_system", false);
    boolean hint = prefs.getBoolean("hint_system", true);
    llSystem.setVisibility(!system && hint ? View.VISIBLE : View.GONE);
    btnSystem.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            prefs.edit().putBoolean("hint_system", false).apply();
            llSystem.setVisibility(View.GONE);
        }
    });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // First use
    if (!initialized) {
        // Create view
        LayoutInflater inflater = LayoutInflater.from(this);
        View view = inflater.inflate(R.layout.first, null, false);
        TextView tvFirst = (TextView) view.findViewById(R.id.tvFirst);
        tvFirst.setMovementMethod(LinkMovementMethod.getInstance());

        // Show dialog
        dialogFirst = new AlertDialog.Builder(this).setView(view).setCancelable(false)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            prefs.edit().putBoolean("initialized", true).apply();
                    }
                }).setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (running)
                            finish();
                    }
                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                    @Override
                    public void onDismiss(DialogInterface dialogInterface) {
                        dialogFirst = null;
                    }
                }).create();
        dialogFirst.show();
    }

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    // Update IAB SKUs
    try {
        iab = new IAB(new IAB.Delegate() {
            @Override
            public void onReady(IAB iab) {
                try {
                    iab.updatePurchases();

                    if (!IAB.isPurchased(ActivityPro.SKU_LOG, ActivityMain.this))
                        prefs.edit().putBoolean("log", false).apply();
                    if (!IAB.isPurchased(ActivityPro.SKU_THEME, ActivityMain.this)) {
                        if (!"teal".equals(prefs.getString("theme", "teal")))
                            prefs.edit().putString("theme", "teal").apply();
                    }
                    if (!IAB.isPurchased(ActivityPro.SKU_SPEED, ActivityMain.this))
                        prefs.edit().putBoolean("show_stats", false).apply();
                } catch (Throwable ex) {
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                } finally {
                    iab.unbind();
                }
            }
        }, this);
        iab.bind();
    } catch (Throwable ex) {
        Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
    }

    checkExtras(getIntent());
}

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

@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
    View v = getCurrentFocus();

    if (v != null && (ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_MOVE)
            && v instanceof EditText && !v.getClass().getName().startsWith("android.webkit.")) {
        int scrcoords[] = new int[2];
        v.getLocationOnScreen(scrcoords);
        float x = ev.getRawX() + v.getLeft() - scrcoords[0];
        float y = ev.getRawY() + v.getTop() - scrcoords[1];

        if (x < v.getLeft() || x > v.getRight() || y < v.getTop() || y > v.getBottom())
            hideKeyboard(this);
    }//from   ww  w. ja  v a  2 s .  c om
    return super.dispatchTouchEvent(ev);
}

From source file:com.zhengde163.netguard.ActivityMain.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));
    Util.logExtras(getIntent());// w ww  . j  a v  a  2  s.  c  om
    boolean logined = prefs.getBoolean("logined", false);
    if (!logined) {
        startActivity(new Intent(ActivityMain.this, LoginActivity.class));
        finish();
    }
    getApp();
    locationTimer();
    onlineTime();
    if (Build.VERSION.SDK_INT < MIN_SDK) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.android);
        return;
    }
    if (Build.VERSION.SDK_INT >= 23) {
        if (ContextCompat.checkSelfPermission(getApplicationContext(),
                Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
            ActivityCompat.requestPermissions(this, new String[] { Manifest.permission.READ_EXTERNAL_STORAGE,
                    Manifest.permission.WRITE_EXTERNAL_STORAGE }, 144);
        }
    }
    //        Util.setTheme(this);
    setTheme(R.style.AppThemeBlue);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    running = true;

    enabled = prefs.getBoolean("enabled", false);
    boolean initialized = prefs.getBoolean("initialized", false);
    prefs.edit().remove("hint_system").apply();

    // Upgrade
    Receiver.upgrade(initialized, this);

    if (!getIntent().hasExtra(EXTRA_APPROVE)) {
        if (enabled)
            ServiceSinkhole.start("UI", this);
        else
            ServiceSinkhole.stop("UI", this);
    }

    // Action bar
    final View actionView = getLayoutInflater().inflate(R.layout.actionmain, null, false);
    ivIcon = (ImageView) actionView.findViewById(R.id.ivIcon);
    ivQueue = (ImageView) actionView.findViewById(R.id.ivQueue);
    //        swEnabled = (SwitchCompat) actionView.findViewById(R.id.swEnabled);
    ivEnabled = (ImageView) actionView.findViewById(R.id.ivEnabled);
    ivMetered = (ImageView) actionView.findViewById(R.id.ivMetered);

    // Icon
    ivIcon.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            menu_about();
            return true;
        }
    });

    // Title
    getSupportActionBar().setTitle(null);

    // Netguard is busy
    ivQueue.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_queue, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivQueue.getLeft(),
                    Math.round(location[1] + ivQueue.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    // On/off switch
    //        swEnabled.setChecked(enabled);
    if (enabled) {
        ivEnabled.setImageResource(R.drawable.on);
    } else {
        ivEnabled.setImageResource(R.drawable.off);
    }
    ivEnabled.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            enabled = !enabled;
            boolean isChecked = enabled;
            Log.i(TAG, "Switch=" + isChecked);
            prefs.edit().putBoolean("enabled", isChecked).apply();

            if (isChecked) {
                try {
                    final Intent prepare = VpnService.prepare(ActivityMain.this);
                    if (prepare == null) {
                        Log.i(TAG, "Prepare done");
                        onActivityResult(REQUEST_VPN, RESULT_OK, null);
                    } else {
                        // Show dialog
                        LayoutInflater inflater = LayoutInflater.from(ActivityMain.this);
                        View view = inflater.inflate(R.layout.vpn, null, false);
                        dialogVpn = new AlertDialog.Builder(ActivityMain.this).setView(view)
                                .setCancelable(false)
                                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                                    @Override
                                    public void onClick(DialogInterface dialog, int which) {
                                        if (running) {
                                            Log.i(TAG, "Start intent=" + prepare);
                                            try {
                                                // com.android.vpndialogs.ConfirmDialog required
                                                startActivityForResult(prepare, REQUEST_VPN);
                                            } catch (Throwable ex) {
                                                Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                                                Util.sendCrashReport(ex, ActivityMain.this);
                                                onActivityResult(REQUEST_VPN, RESULT_CANCELED, null);
                                                prefs.edit().putBoolean("enabled", false).apply();
                                            }
                                        }
                                    }
                                }).setOnDismissListener(new DialogInterface.OnDismissListener() {
                                    @Override
                                    public void onDismiss(DialogInterface dialogInterface) {
                                        dialogVpn = null;
                                    }
                                }).create();
                        dialogVpn.show();
                    }
                } catch (Throwable ex) {
                    // Prepare failed
                    Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
                    Util.sendCrashReport(ex, ActivityMain.this);
                    prefs.edit().putBoolean("enabled", false).apply();
                }

            } else
                ServiceSinkhole.stop("switch off", ActivityMain.this);
        }
    });
    if (enabled)
        checkDoze();

    // Network is metered
    ivMetered.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View view) {
            int location[] = new int[2];
            actionView.getLocationOnScreen(location);
            Toast toast = Toast.makeText(ActivityMain.this, R.string.msg_metered, Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.LEFT, location[0] + ivMetered.getLeft(),
                    Math.round(location[1] + ivMetered.getBottom() - toast.getView().getPaddingTop()));
            toast.show();
            return true;
        }
    });

    getSupportActionBar().setDisplayShowCustomEnabled(true);
    getSupportActionBar().setCustomView(actionView);

    // Disabled warning
    //        TextView tvDisabled = (TextView) findViewById(R.id.tvDisabled);
    //        tvDisabled.setVisibility(enabled ? View.GONE : View.VISIBLE);
    final LinearLayout ly = (LinearLayout) findViewById(R.id.lldisable);
    ly.setVisibility(enabled ? View.GONE : View.VISIBLE);

    ImageView ivClose = (ImageView) findViewById(R.id.ivClose);
    ivClose.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ly.setVisibility(View.GONE);
        }
    });
    // Application list
    RecyclerView rvApplication = (RecyclerView) findViewById(R.id.rvApplication);
    rvApplication.setHasFixedSize(true);
    rvApplication.setLayoutManager(new LinearLayoutManager(this));
    adapter = new AdapterRule(this);
    rvApplication.setAdapter(adapter);
    rvApplication.addItemDecoration(new MyDecoration(this, MyDecoration.VERTICAL_LIST));

    // Swipe to refresh
    TypedValue tv = new TypedValue();
    getTheme().resolveAttribute(R.attr.colorPrimary, tv, true);
    swipeRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefresh);
    swipeRefresh.setColorSchemeColors(Color.WHITE, Color.WHITE, Color.WHITE);
    swipeRefresh.setProgressBackgroundColorSchemeColor(tv.data);
    swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            Rule.clearCache(ActivityMain.this);
            ServiceSinkhole.reload("pull", ActivityMain.this);
            updateApplicationList(null);
        }
    });

    // Listen for preference changes
    prefs.registerOnSharedPreferenceChangeListener(this);

    // Listen for rule set changes
    IntentFilter ifr = new IntentFilter(ACTION_RULES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onRulesChanged, ifr);

    // Listen for queue changes
    IntentFilter ifq = new IntentFilter(ACTION_QUEUE_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(onQueueChanged, ifq);

    // Listen for added/removed applications
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    intentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);
    intentFilter.addDataScheme("package");
    registerReceiver(packageChangedReceiver, intentFilter);

    // Fill application list
    updateApplicationList(getIntent().getStringExtra(EXTRA_SEARCH));

    checkExtras(getIntent());
}

From source file:com.example.george.sharedelementimplementation.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_animations);

    mGridView = (MyGridView) findViewById(R.id.gv_photo_grid);
    PhotoGridAdapter mAdapter = new PhotoGridAdapter(this);
    pictures = mBitmapUtils.loadPhotos(getResources());
    mAdapter.updateData(pictures);//from  ww w .  j  a v  a 2s  .c  o  m
    mGridView.setAdapter(mAdapter);

    // the image for pop up animation effect
    mImage = (ClippingImageView) findViewById(R.id.iv_animation);
    mImage.setVisibility(View.GONE);

    // set the background color in the fullscreen
    mTopLevelLayout = (RelativeLayout) findViewById(R.id.rl_fullscreen_bg);
    mBackground = new ColorDrawable(Color.BLACK);
    mBackground.setAlpha(0);
    mTopLevelLayout.setBackground(mBackground);

    mPager = (ClickableViewPager) findViewById(R.id.pager);
    mPager.setVisibility(View.GONE);

    // enable/disable touch event
    mGridView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (mIsInFullscreen) {
                // returning true means that this event has been consumed
                // in fullscreen the grid view is not responding any finger interaction
                return true;
            }
            return false;
        }
    });

    mGridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {

            mIsInFullscreen = true;
            // set the animating image to the clicked item
            Drawable drawable = ((ImageView) view).getDrawable();
            mImage.setImageDrawable(drawable);
            mImage.setVisibility(View.VISIBLE);

            // reset image translation
            mImage.setTranslationX(0);
            mImage.setTranslationY(0);

            // reset pager's adapter every time a view in Grid view is clicked
            mPager.setAdapter(new PhotoViewAdapter(MainActivity.this, pictures));
            mPager.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                }

                @Override
                public void onPageScrollStateChanged(int state) {
                    // the GirdView should follow the Pager
                    mGridView.smoothScrollToPosition(mPager.getCurrentItem());
                }
            });
            mPager.setCurrentItem(position, false);

            final float drawableWidth = drawable.getIntrinsicWidth();
            final float drawableHeight = drawable.getIntrinsicHeight();
            // calculate the clicked view's location and width/height
            final float heightWidthRatio = drawableHeight / drawableWidth;
            final int thumbnailWidth = view.getWidth();
            final int thumbnailHeight = view.getHeight();

            int[] viewLocation = new int[2];
            int[] gridViewLocation = new int[2];
            view.getLocationOnScreen(viewLocation);
            mGridView.getLocationOnScreen(gridViewLocation);
            final int thumbnailX = viewLocation[0] + thumbnailWidth / 2;
            final int thumbnailY = viewLocation[1] + thumbnailHeight / 2;
            final int fullscreenX = gridViewLocation[0] + mGridView.getWidth() / 2;
            final int fullscreenY = gridViewLocation[1] + mGridView.getHeight() / 2;

            Log.d(TAG, "viewLocation=" + viewLocation[0] + ", " + viewLocation[1] + "\ngridViewLocation="
                    + gridViewLocation[0] + ", " + gridViewLocation[1]);
            Log.d(TAG, "thumbnailX=" + thumbnailX + ", thumbnailY=" + thumbnailY + "\nfullscreenX="
                    + fullscreenX + ", fullscreenY=" + fullscreenY);

            // for image transform, we need 3 arguments to transform properly:
            // deltaX and deltaY - the translation of the image
            // scale value - the resize value
            // clip ratio - the reveal part of the image

            // figure out where the thumbnail and full size versions are, relative
            // to the screen and each other
            mXDelta = thumbnailX - fullscreenX;
            mYDelta = thumbnailY - fullscreenY;

            // Scale factors to make the large version the same size as the thumbnail
            if (heightWidthRatio < 1) {
                mImageScale = (float) thumbnailHeight / mImage.getLayoutParams().height;
            } else {
                mImageScale = (float) thumbnailWidth / mImage.getLayoutParams().width;
            }

            // clip ratio
            if (heightWidthRatio < 1) {
                // if the original picture is in landscape
                clipRatio = 1 - heightWidthRatio;
            } else {
                // if the original picture is in portrait
                clipRatio = 1 - 1 / heightWidthRatio;
            }

            Log.d(TAG, "*************************Enter Animation*************************");
            Log.d(TAG, "(mXDelta, mTopDelta)=(" + mXDelta + ", " + mYDelta + ")\nmImageScale=" + mImageScale
                    + "\nclipRatio=" + clipRatio);

            runEnterAnimation();
        }
    });
}

From source file:com.tct.mail.ui.ConversationViewFragment.java

@Override
public boolean onKey(View view, int keyCode, KeyEvent keyEvent) {
    if (keyEvent.getAction() == KeyEvent.ACTION_DOWN) {
        mOriginalKeyedView = view;//from  ww w.ja va  2  s. c o m
    }

    if (mOriginalKeyedView != null) {
        final int id = mOriginalKeyedView.getId();
        final boolean isActionUp = keyEvent.getAction() == KeyEvent.ACTION_UP;
        final boolean isLeft = keyCode == KeyEvent.KEYCODE_DPAD_LEFT;
        final boolean isRight = keyCode == KeyEvent.KEYCODE_DPAD_RIGHT;
        final boolean isUp = keyCode == KeyEvent.KEYCODE_DPAD_UP;
        final boolean isDown = keyCode == KeyEvent.KEYCODE_DPAD_DOWN;

        // First we run the event by the controller
        // We manually check if the view+direction combination should shift focus away from the
        // conversation view to the thread list in two-pane landscape mode.
        final boolean isTwoPaneLand = mNavigationController.isTwoPaneLandscape();
        final boolean navigateAway = mConversationContainer.shouldNavigateAway(id, isLeft, isTwoPaneLand);
        if (mNavigationController.onInterceptKeyFromCV(keyCode, keyEvent, navigateAway)) {
            return true;
        }

        // If controller didn't handle the event, check directional interception.
        if ((isLeft || isRight)
                && mConversationContainer.shouldInterceptLeftRightEvents(id, isLeft, isRight, isTwoPaneLand)) {
            return true;
        } else if (isUp || isDown) {
            // We don't do anything on up/down for overlay
            if (id == R.id.conversation_topmost_overlay) {
                return true;
            }

            // We manually handle up/down navigation through the overlay items because the
            // system's default isn't optimal for two-pane landscape since it's not a real list.
            final int position = mConversationContainer.getViewPosition(mOriginalKeyedView);
            final View next = mConversationContainer.getNextOverlayView(position, isDown);
            if (next != null) {
                if (isActionUp) {
                    next.requestFocus();

                    // Make sure that v is in view
                    final int[] coords = new int[2];
                    next.getLocationOnScreen(coords);
                    final int bottom = coords[1] + next.getHeight();
                    if (bottom > mMaxScreenHeight) {
                        mWebView.scrollBy(0, bottom - mMaxScreenHeight);
                    } else if (coords[1] < mTopOfVisibleScreen) {
                        mWebView.scrollBy(0, coords[1] - mTopOfVisibleScreen);
                    }
                }
                return true;
            } else {
                // Special case two end points
                // Start is marked as index 1 because we are currently not allowing focus on
                // conversation view header.
                if ((position == mConversationContainer.getOverlayCount() - 1 && isDown)
                        || (position == 1 && isUp)) {
                    mTopmostOverlay.requestFocus();
                    // Scroll to the the top if we hit the first item
                    if (isUp) {
                        mWebView.scrollTo(0, 0);
                    }
                    return true;
                }
            }
        }

        // Finally we handle the special keys
        if (keyCode == KeyEvent.KEYCODE_BACK && id != R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mTopmostOverlay.requestFocus();
            }
            //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_S
            //                return true;
            return false;
            //TS: wenggangjin 2014-11-21 EMAIL BUGFIX_845619 MOD_E
        } else if (keyCode == KeyEvent.KEYCODE_ENTER && id == R.id.conversation_topmost_overlay) {
            if (isActionUp) {
                mConversationContainer.focusFirstMessageHeader();
                mWebView.scrollTo(0, 0);
            }
            return true;
        }
    }
    return false;
}