Example usage for android.view View getViewTreeObserver

List of usage examples for android.view View getViewTreeObserver

Introduction

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

Prototype

public ViewTreeObserver getViewTreeObserver() 

Source Link

Document

Returns the ViewTreeObserver for this view's hierarchy.

Usage

From source file:com.bridgeconn.autographago.ui.activities.SettingsActivity.java

private void showLanguageDialog(List<String> languages) {
    Realm realm = Realm.getDefaultInstance();
    ArrayList<LanguageModel> languageModels = query(realm, new AllSpecifications.AllLanguages(),
            new AllMappers.LanguageMapper());
    for (Iterator<String> iterator = languages.iterator(); iterator.hasNext();) {
        String lan = iterator.next();
        for (LanguageModel languageModel : languageModels) {
            if (languageModel.getLanguageName().equals(lan)) {
                if (languageModel.getVersionModels().size() == 2) {
                    iterator.remove();//from  w  w  w .  j a  v  a2 s  .c  o m
                }
            }
        }
    }
    realm.close();
    if (isFinishing()) {
        return;
    }

    if (languages.size() == 0) {
        Toast.makeText(this, getResources().getString(R.string.no_new_languages_available), Toast.LENGTH_SHORT)
                .show();
        return;
    }
    AlertDialog.Builder builder = null;
    switch (SharedPrefs.getReadingMode()) {
    case Day: {
        builder = new AlertDialog.Builder(this, R.style.DialogThemeLight);
        break;
    }
    case Night: {
        builder = new AlertDialog.Builder(this, R.style.DialogThemeDark);
        break;
    }
    }

    final View view = LayoutInflater.from(this).inflate(R.layout.dialog_languages,
            (ViewGroup) findViewById(android.R.id.content), false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_items);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    builder.setView(view);

    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        int maxHeight = UtilFunctions.dpToPx(SettingsActivity.this, 300);

        @Override
        public void onGlobalLayout() {
            if (view.getHeight() > maxHeight)
                view.getLayoutParams().height = maxHeight;
        }
    });

    builder.setNegativeButton(getString(R.string.cancel).toUpperCase(), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.setTitle(getString(R.string.select_language));

    AlertDialog dialog = builder.create();
    dialog.show();

    DownloadDialogAdapter dialogAdapter = new DownloadDialogAdapter(this, dialog, languages, null, null);
    recyclerView.setAdapter(dialogAdapter);
}

From source file:com.bridgeconn.autographago.ui.activities.SettingsActivity.java

private void showVersionDialog(List<String> versions, String language) {
    Realm realm = Realm.getDefaultInstance();
    ArrayList<LanguageModel> languageModels = query(realm, new AllSpecifications.AllLanguages(),
            new AllMappers.LanguageMapper());
    for (Iterator<String> iterator = versions.iterator(); iterator.hasNext();) {
        String ver = iterator.next();
        for (LanguageModel languageModel : languageModels) {
            if (languageModel.getLanguageName().equals(language)) {
                for (VersionModel versionModel : languageModel.getVersionModels()) {
                    if (versionModel.getVersionCode().equals(ver)) {
                        iterator.remove();
                    }/*from   w  ww .  ja v  a 2  s . c o  m*/
                }
            }
        }
    }
    realm.close();
    if (isFinishing()) {
        return;
    }

    if (versions.size() == 0) {
        Toast.makeText(this, getResources().getString(R.string.no_new_versions_available), Toast.LENGTH_SHORT)
                .show();
        return;
    }

    AlertDialog.Builder builder = null;
    switch (SharedPrefs.getReadingMode()) {
    case Day: {
        builder = new AlertDialog.Builder(this, R.style.DialogThemeLight);
        break;
    }
    case Night: {
        builder = new AlertDialog.Builder(this, R.style.DialogThemeDark);
        break;
    }
    }

    final View view = LayoutInflater.from(this).inflate(R.layout.dialog_languages,
            (ViewGroup) findViewById(android.R.id.content), false);
    RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.list_items);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setHasFixedSize(true);
    builder.setView(view);

    view.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        int maxHeight = UtilFunctions.dpToPx(SettingsActivity.this, 300);

        @Override
        public void onGlobalLayout() {
            if (view.getHeight() > maxHeight)
                view.getLayoutParams().height = maxHeight;
        }
    });

    builder.setNegativeButton(getString(R.string.cancel).toUpperCase(), new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });

    builder.setTitle(getString(R.string.select_version));

    AlertDialog dialog = builder.create();
    dialog.show();

    DownloadDialogAdapter dialogAdapter = new DownloadDialogAdapter(this, dialog, null, versions, language);
    recyclerView.setAdapter(dialogAdapter);
}

From source file:plugin.google.maps.CordovaGoogleMaps.java

@SuppressLint("NewApi")
@Override//from w w w.  jav  a  2  s  .  co m
public void initialize(final CordovaInterface cordova, final CordovaWebView webView) {
    super.initialize(cordova, webView);
    if (root != null) {
        return;
    }
    activity = cordova.getActivity();
    final View view = webView.getView();
    view.getViewTreeObserver().addOnScrollChangedListener(CordovaGoogleMaps.this);
    root = (ViewGroup) view.getParent();

    Method[] classMethods = this.getClass().getMethods();
    for (int i = 0; i < classMethods.length; i++) {
        String methodName = classMethods[i].getName();
        methods.put(methodName, methodName.hashCode());
    }

    pluginManager = webView.getPluginManager();

    cordova.getActivity().runOnUiThread(new Runnable() {
        @SuppressLint("NewApi")
        public void run() {

            // Enable this, webView makes draw cache on the Android action bar issue.
            //View view = webView.getView();
            //if (Build.VERSION.SDK_INT >= 21 || "org.xwalk.core.XWalkView".equals(view.getClass().getName())){
            //  view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
            //  Log.d("Layout", "--> view =" + view.isHardwareAccelerated()); //always false
            //}

            // ------------------------------
            // Check of Google Play Services
            // ------------------------------
            int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity);

            Log.d(TAG,
                    "----> checkGooglePlayServices = " + (ConnectionResult.SUCCESS == checkGooglePlayServices));

            if (checkGooglePlayServices != ConnectionResult.SUCCESS) {
                // google play services is missing!!!!
                /*
                 * Returns status code indicating whether there was an error. Can be one
                 * of following in ConnectionResult: SUCCESS, SERVICE_MISSING,
                 * SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID.
                 */
                Log.e(TAG, "---Google Play Services is not available: "
                        + GooglePlayServicesUtil.getErrorString(checkGooglePlayServices));

                boolean isNeedToUpdate = false;

                String errorMsg = "Google Maps Android API v2 is not available for some reason on this device. Do you install the latest Google Play Services from Google Play Store?";
                switch (checkGooglePlayServices) {
                case ConnectionResult.DEVELOPER_ERROR:
                    errorMsg = "The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information.";
                    break;
                case ConnectionResult.INTERNAL_ERROR:
                    errorMsg = "An internal error of Google Play Services occurred. Please retry, and it should resolve the problem.";
                    break;
                case ConnectionResult.INVALID_ACCOUNT:
                    errorMsg = "You attempted to connect to the service with an invalid account name specified.";
                    break;
                case ConnectionResult.LICENSE_CHECK_FAILED:
                    errorMsg = "The application is not licensed to the user. This error is not recoverable and will be treated as fatal.";
                    break;
                case ConnectionResult.NETWORK_ERROR:
                    errorMsg = "A network error occurred. Please retry, and it should resolve the problem.";
                    break;
                case ConnectionResult.SERVICE_DISABLED:
                    errorMsg = "The installed version of Google Play services has been disabled on this device. Please turn on Google Play Services.";
                    break;
                case ConnectionResult.SERVICE_INVALID:
                    errorMsg = "The version of the Google Play services installed on this device is not authentic. Please update the Google Play Services from Google Play Store.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SERVICE_MISSING:
                    errorMsg = "Google Play services is missing on this device. Please install the Google Play Services.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED:
                    errorMsg = "The installed version of Google Play services is out of date. Please update the Google Play Services from Google Play Store.";
                    isNeedToUpdate = true;
                    break;
                case ConnectionResult.SIGN_IN_REQUIRED:
                    errorMsg = "You attempted to connect to the service but you are not signed in. Please check the Google Play Services configuration";
                    break;
                default:
                    isNeedToUpdate = true;
                    break;
                }

                final boolean finalIsNeedToUpdate = isNeedToUpdate;
                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);
                alertDialogBuilder.setMessage(errorMsg).setCancelable(false).setPositiveButton("Close",
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                                if (finalIsNeedToUpdate) {
                                    try {
                                        activity.startActivity(new Intent(Intent.ACTION_VIEW,
                                                Uri.parse("market://details?id=com.google.android.gms")));
                                    } catch (android.content.ActivityNotFoundException anfe) {
                                        activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(
                                                "http://play.google.com/store/apps/details?id=appPackageName")));
                                    }
                                }
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();

                Log.e(TAG, "Google Play Services is not available.");
                return;
            }

            webView.getView().setBackgroundColor(Color.TRANSPARENT);
            webView.getView().setOverScrollMode(View.OVER_SCROLL_NEVER);
            mPluginLayout = new MyPluginLayout(webView, activity);

            // Check the API key
            ApplicationInfo appliInfo = null;
            try {
                appliInfo = activity.getPackageManager().getApplicationInfo(activity.getPackageName(),
                        PackageManager.GET_META_DATA);
            } catch (NameNotFoundException e) {
            }

            String API_KEY = appliInfo.metaData.getString("com.google.android.maps.v2.API_KEY");
            if ("API_KEY_FOR_ANDROID".equals(API_KEY)) {

                AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity);

                alertDialogBuilder.setMessage(
                        "Please replace 'API_KEY_FOR_ANDROID' in the platforms/android/AndroidManifest.xml with your API Key!")
                        .setCancelable(false).setPositiveButton("Close", new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                dialog.dismiss();
                            }
                        });
                AlertDialog alertDialog = alertDialogBuilder.create();

                // show it
                alertDialog.show();
            }

            CURRENT_URL = webView.getUrl();

            //------------------------------
            // Initialize Google Maps SDK
            //------------------------------
            if (!initialized) {
                try {
                    MapsInitializer.initialize(cordova.getActivity());
                    initialized = true;
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

        }
    });

}

From source file:com.android.incallui.CircularRevealActivity.java

private void setupDecorView(final Point touchPoint, MaterialPalette palette) {
    final View view = getWindow().getDecorView();

    // The circle starts from an initial size of 0 so clip it such that it is invisible. When
    // the animation later starts, this clip will be clobbered by the circular reveal clip.
    // See ViewAnimationUtils.createCircularReveal.
    view.setOutlineProvider(new ViewOutlineProvider() {
        @Override/*from   w w  w . j av a2 s.c  om*/
        public void getOutline(View view, Outline outline) {
            // Using (0, 0, 0, 0) will not work since the outline will simply be treated as
            // an empty outline.
            outline.setOval(-1, -1, 0, 0);
        }
    });
    view.setClipToOutline(true);

    if (palette != null) {
        view.findViewById(R.id.outgoing_call_animation_circle).setBackgroundColor(palette.mPrimaryColor);
        getWindow().setStatusBarColor(palette.mSecondaryColor);
    }

    view.getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            final ViewTreeObserver vto = view.getViewTreeObserver();
            if (vto.isAlive()) {
                vto.removeOnPreDrawListener(this);
            }
            final Animator animator = getRevealAnimator(touchPoint);
            // Since this animator is a RenderNodeAnimator (native animator), add an arbitary
            // start delay to force the onAnimationStart callback to happen later on the UI
            // thread. Otherwise it would happen right away inside animator.start()
            animator.setStartDelay(5);
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    InCallPresenter.getInstance().onCircularRevealStarted(CircularRevealActivity.this);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    view.setClipToOutline(false);
                    super.onAnimationEnd(animation);
                }
            });
            animator.start();
            return false;
        }
    });
}

From source file:com.irccloud.android.activity.UploadsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (ColorFormatter.file_uri_template != null)
        template = UriTemplate.fromTemplate(ColorFormatter.file_uri_template);
    super.onCreate(savedInstanceState);
    if (Build.VERSION.SDK_INT >= 21) {
        Bitmap cloud = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);
        setTaskDescription(new ActivityManager.TaskDescription(getResources().getString(R.string.app_name),
                cloud, 0xFFF2F7FC));//from w  w  w. ja v a 2  s .com
        cloud.recycle();
    }

    if (Build.VERSION.SDK_INT >= 14) {
        try {
            java.io.File httpCacheDir = new java.io.File(getCacheDir(), "http");
            long httpCacheSize = 10 * 1024 * 1024; // 10 MiB
            HttpResponseCache.install(httpCacheDir, httpCacheSize);
        } catch (IOException e) {
            Log.i("IRCCloud", "HTTP response cache installation failed:" + e);
        }
    }
    setContentView(R.layout.ignorelist);

    if (getSupportActionBar() != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        getSupportActionBar().setHomeAsUpIndicator(R.drawable.abc_ic_ab_back_mtrl_am_alpha);
        getSupportActionBar().setBackgroundDrawable(getResources().getDrawable(R.drawable.actionbar));
        getSupportActionBar().setElevation(0);
    }

    if (savedInstanceState != null && savedInstanceState.containsKey("cid")) {
        cid = savedInstanceState.getInt("cid");
        to = savedInstanceState.getString("to");
        msg = savedInstanceState.getString("msg");
        page = savedInstanceState.getInt("page");
        File[] files = (File[]) savedInstanceState.getSerializable("adapter");
        for (File f : files) {
            adapter.addFile(f);
        }
        adapter.notifyDataSetChanged();
    }

    footer = getLayoutInflater().inflate(R.layout.messageview_header, null);
    ListView listView = (ListView) findViewById(android.R.id.list);
    listView.setAdapter(adapter);
    listView.addFooterView(footer);
    listView.setOnScrollListener(new AbsListView.OnScrollListener() {
        @Override
        public void onScrollStateChanged(AbsListView absListView, int i) {

        }

        @Override
        public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
            if (canLoadMore && firstVisibleItem + visibleItemCount > totalItemCount - 4) {
                canLoadMore = false;
                new FetchFilesTask().execute((Void) null);
            }
        }
    });
    listView.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {

        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
            final File f = (File) adapter.getItem(i);

            AlertDialog.Builder builder = new AlertDialog.Builder(UploadsActivity.this);
            builder.setInverseBackgroundForced(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB);
            final View v = getLayoutInflater().inflate(R.layout.dialog_upload, null);
            final EditText messageinput = (EditText) v.findViewById(R.id.message);
            messageinput.setText(msg);
            final ImageView thumbnail = (ImageView) v.findViewById(R.id.thumbnail);

            v.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
                @Override
                public void onGlobalLayout() {
                    if (messageinput.hasFocus()) {
                        v.post(new Runnable() {
                            @Override
                            public void run() {
                                v.scrollTo(0, v.getBottom());
                            }
                        });
                    }
                }
            });

            if (f.mime_type.startsWith("image/")) {
                try {
                    thumbnail.setImageBitmap(f.image);
                    thumbnail.setVisibility(View.VISIBLE);
                    thumbnail.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {
                            Intent i = new Intent(UploadsActivity.this, ImageViewerActivity.class);
                            i.setData(Uri.parse(f.url));
                            startActivity(i);
                        }
                    });
                    thumbnail.setClickable(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                thumbnail.setVisibility(View.GONE);
            }

            ((TextView) v.findViewById(R.id.filesize)).setText(f.metadata);
            v.findViewById(R.id.filename).setVisibility(View.GONE);
            v.findViewById(R.id.filename_heading).setVisibility(View.GONE);

            builder.setTitle("Send A File To " + to);
            builder.setView(v);
            builder.setPositiveButton("Send", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String message = messageinput.getText().toString();
                    if (message.length() > 0)
                        message += " ";
                    message += f.url;

                    dialog.dismiss();
                    if (getParent() == null) {
                        setResult(Activity.RESULT_OK);
                    } else {
                        getParent().setResult(Activity.RESULT_OK);
                    }
                    finish();

                    NetworkConnection.getInstance().say(cid, to, message);
                }
            });
            builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            AlertDialog d = builder.create();
            d.setOwnerActivity(UploadsActivity.this);
            d.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
            d.show();
        }
    });
}

From source file:net.naonedbus.card.impl.HoraireCard.java

@Override
protected void bindView(final Context context, final View base, final View view) {

    mTerminusView = (ViewGroup) view.findViewById(R.id.terminus);

    mHoraireViews.clear();//from   w w w  . j  a  v a 2s .co  m
    mDelaiViews.clear();

    ViewHelper.findViewsByTag(view, context.getString(R.string.cardHoraireTag), new OnTagFoundHandler() {
        @Override
        public void onTagFound(final View v) {
            mHoraireViews.add((TextView) v);
            setTypefaceRobotoLight((TextView) v);
        }
    });

    ViewHelper.findViewsByTag(view, context.getString(R.string.cardDelaiTag), new OnTagFoundHandler() {
        @Override
        public void onTagFound(final View v) {
            mDelaiViews.add((TextView) v);
        }
    });

    final ViewTreeObserver obs = base.getViewTreeObserver();
    obs.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            if (base.getMeasuredWidth() != 0) {
                base.getViewTreeObserver().removeOnPreDrawListener(this);
                fillView((ViewGroup) base, (ViewGroup) view);
            }
            return true;
        }
    });

}

From source file:com.undatech.opaque.RemoteCanvasActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    // TODO: Implement left-icon
    //requestWindowFeature(Window.FEATURE_LEFT_ICON);
    //setFeatureDrawableResource(Window.FEATURE_LEFT_ICON, R.drawable.icon); 

    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);

    handler = new Handler();
    setContentView(R.layout.canvas);/* w  w w  .  j av  a  2s  . c  om*/
    canvas = (RemoteCanvas) findViewById(R.id.canvas);

    Intent i = getIntent();
    String vvFileName = startSessionFromVvFile(i);
    if (vvFileName == null) {
        android.util.Log.d(TAG, "Initializing session from connection settings.");
        connection = (ConnectionSettings) i.getSerializableExtra("com.undatech.opaque.ConnectionSettings");
        canvas.initialize(connection);
    } else {
        canvas.initialize(vvFileName, connection);
    }

    canvas.setOnKeyListener(this);
    canvas.setFocusableInTouchMode(true);
    canvas.setDrawingCacheEnabled(false);

    // If rotation is disabled, fix the orientation to the current one.
    if (!connection.isRotationEnabled()) {
        int orientation = getResources().getConfiguration().orientation;
        if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
        } else {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
        }
    }

    // This code detects when the soft keyboard is up and sets an appropriate visibleHeight in the canvas.
    // When the keyboard is gone, it resets visibleHeight and pans zero distance to prevent us from being
    // below the desktop image (if we scrolled all the way down when the keyboard was up).
    // TODO: Move this into a separate thread, and post the visibility changes to the handler.
    //       to avoid occupying the UI thread with this.
    final View rootView = ((ViewGroup) findViewById(android.R.id.content)).getChildAt(0);
    rootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            Rect r = new Rect();

            rootView.getWindowVisibleDisplayFrame(r);

            // To avoid setting the visible height to a wrong value after an screen unlock event
            // (when r.bottom holds the width of the screen rather than the height due to a rotation)
            // we make sure r.top is zero (i.e. there is no notification bar and we are in full-screen mode)
            // It's a bit of a hack.
            if (r.top == 0) {
                if (canvas.myDrawable != null) {
                    canvas.setVisibleDesktopHeight(r.bottom);
                    canvas.relativePan(0, 0);
                }
            }

            // Enable/show the zoomer if the keyboard is gone, and disable/hide otherwise.
            // We detect the keyboard if more than 19% of the screen is covered.
            int offset = 0;
            int rootViewHeight = rootView.getHeight();
            if (r.bottom > rootViewHeight * 0.81) {
                offset = rootViewHeight - r.bottom;
                // Soft Kbd gone, shift the meta keys and arrows down.
                if (layoutKeys != null) {
                    layoutKeys.offsetTopAndBottom(offset);
                    keyStow.offsetTopAndBottom(offset);
                    if (prevBottomOffset != offset) {
                        setExtraKeysVisibility(View.GONE, false);
                        canvas.invalidate();
                        kbdIcon.enable();
                    }
                }
            } else {
                offset = r.bottom - rootViewHeight;
                //  Soft Kbd up, shift the meta keys and arrows up.
                if (layoutKeys != null) {
                    layoutKeys.offsetTopAndBottom(offset);
                    keyStow.offsetTopAndBottom(offset);
                    if (prevBottomOffset != offset) {
                        setExtraKeysVisibility(View.VISIBLE, true);
                        canvas.invalidate();
                        kbdIcon.hide();
                        kbdIcon.disable();
                    }
                }
            }
            setKeyStowDrawableAndVisibility();
            prevBottomOffset = offset;
        }
    });

    kbdIcon = (ZoomControls) findViewById(R.id.zoomer);
    kbdIcon.hide();
    kbdIcon.setOnZoomKeyboardClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            InputMethodManager inputMgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            inputMgr.toggleSoftInput(0, 0);
        }
    });

    // Initialize and define actions for on-screen keys.
    initializeOnScreenKeys();

    myVibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE);

    // Initialize map from XML IDs to input handlers.
    inputHandlerIdMap = new HashMap<Integer, InputHandler>();
    inputHandlerIdMap.put(R.id.inputMethodDirectSwipePan,
            new InputHandlerDirectSwipePan(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodDirectDragPan,
            new InputHandlerDirectDragPan(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodTouchpad, new InputHandlerTouchpad(this, canvas, myVibrator));
    inputHandlerIdMap.put(R.id.inputMethodSingleHanded, new InputHandlerSingleHanded(this, canvas, myVibrator));

    android.util.Log.e(TAG, "connection.getInputMethod(): " + connection.getInputMethod());
    inputHandler = idToInputHandler(connection.getInputMethod());
}

From source file:com.freerdp.freerdpcore.presentation.SessionActivity.java

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

    // show status bar or make fullscreen?
    if (GlobalSettings.getHideStatusBar())
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    this.setContentView(R.layout.session);
    rladvertising = (AdvertisingView) findViewById(R.id.advertising);
    rladvertising.startImagePlay();/*from   w ww .  j  a  va  2 s. c om*/
    final View activityRootView = findViewById(R.id.session_root_view);
    //
    activityRootView.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            screen_width = activityRootView.getWidth();
            screen_height = activityRootView.getHeight();
            if (!sessionRunning && getIntent() != null) {
                thread = new Thread(SessionActivity.this);
                thread.start();
                sessionRunning = true;
            }
        }
    });

    sessionView = (SessionView) findViewById(R.id.sessionView);
    sessionView.setScaleGestureDetector(new ScaleGestureDetector(this, new PinchZoomListener()));
    sessionView.setSessionViewListener(this);
    sessionView.requestFocus();

    touchPointerView = (TouchPointerView) findViewById(R.id.touchPointerView);
    touchPointerView.setTouchPointerListener(this);

    keyboardMapper = new KeyboardMapper();
    keyboardMapper.init(this);
    keyboardMapper.reset(this);

    modifiersKeyboard = new Keyboard(getApplicationContext(), R.xml.modifiers_keyboard);
    specialkeysKeyboard = new Keyboard(getApplicationContext(), R.xml.specialkeys_keyboard);
    numpadKeyboard = new Keyboard(getApplicationContext(), R.xml.numpad_keyboard);
    cursorKeyboard = new Keyboard(getApplicationContext(), R.xml.cursor_keyboard);

    // hide keyboard below the sessionView
    keyboardView = (KeyboardView) findViewById(R.id.extended_keyboard);
    keyboardView.setKeyboard(specialkeysKeyboard);
    keyboardView.setOnKeyboardActionListener(this);

    modifiersKeyboardView = (KeyboardView) findViewById(R.id.extended_keyboard_header);
    modifiersKeyboardView.setKeyboard(modifiersKeyboard);
    modifiersKeyboardView.setOnKeyboardActionListener(this);

    scrollView = (ScrollView2D) findViewById(R.id.sessionScrollView);
    scrollView.setScrollViewListener(this);
    uiHandler = new UIHandler();
    libFreeRDPBroadcastReceiver = new LibFreeRDPBroadcastReceiver();

    zoomControls = (ZoomControls) findViewById(R.id.zoomControls);
    zoomControls.hide();
    zoomControls.setOnZoomInClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            resetZoomControlsAutoHideTimeout();
            zoomControls.setIsZoomInEnabled(sessionView.zoomIn(ZOOMING_STEP));
            zoomControls.setIsZoomOutEnabled(true);
        }
    });
    zoomControls.setOnZoomOutClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            resetZoomControlsAutoHideTimeout();
            zoomControls.setIsZoomOutEnabled(sessionView.zoomOut(ZOOMING_STEP));
            zoomControls.setIsZoomInEnabled(true);
        }
    });

    toggleMouseButtons = false;

    createDialogs();

    // register freerdp events broadcast receiver
    IntentFilter filter = new IntentFilter();
    filter.addAction(GlobalApp.ACTION_EVENT_FREERDP);
    registerReceiver(libFreeRDPBroadcastReceiver, filter);

    mClipboardManager = ClipboardManagerProxy.getClipboardManager(this);
    mClipboardManager.addClipboardChangedListener(this);

}

From source file:com.android.tv.settings.dialog.DialogFragment.java

private void runDelayedAnim(final Runnable runnable) {
    final View dialogView = getView();
    final View contentView = (View) dialogView.getTag(R.id.content_fragment);

    contentView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override/*from ww  w.j  ava  2 s . c o  m*/
        public void onGlobalLayout() {
            contentView.getViewTreeObserver().removeOnGlobalLayoutListener(this);
            // if we buildLayer() at this time, the texture is
            // actually not created delay a little so we can make
            // sure all hardware layer is created before animation,
            // in that way we can avoid the jittering of start
            // animation
            contentView.postOnAnimationDelayed(runnable, ANIMATE_DELAY);
        }
    });

}