Example usage for android.view.inputmethod InputMethodManager showSoftInput

List of usage examples for android.view.inputmethod InputMethodManager showSoftInput

Introduction

In this page you can find the example usage for android.view.inputmethod InputMethodManager showSoftInput.

Prototype

public boolean showSoftInput(View view, int flags) 

Source Link

Document

Synonym for #showSoftInput(View,int,ResultReceiver) without a result receiver: explicitly request that the current input method's soft input area be shown to the user, if needed.

Usage

From source file:com.jtschohl.androidfirewall.MainActivity.java

/**
 * search function/*  w ww  .  j a  v  a  2 s  . c  o m*/
 */

public void searchapps() {
    final EditText filterText = (EditText) findViewById(R.id.search);
    filterText.addTextChangedListener(filterTextWatcher);
    filterText.post(new Runnable() {
        @Override
        public void run() {
            filterText.requestFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(filterText, InputMethodManager.SHOW_IMPLICIT);
        }
    });
}

From source file:com.igniva.filemanager.activities.MainActivity.java

/**
 * show search view with a circular reveal animation
 *///from ww w .j a v  a2s. c o  m
void revealSearchView() {

    final int START_RADIUS = 16;
    int endRadius = Math.max(toolbar.getWidth(), toolbar.getHeight());

    Animator animator;
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        animator = ViewAnimationUtils.createCircularReveal(searchViewLayout, searchCoords[0] + 32,
                searchCoords[1] - 16, START_RADIUS, endRadius);
    } else {
        // TODO:ViewAnimationUtils.createCircularReveal
        animator = new ObjectAnimator().ofFloat(searchViewLayout, "alpha", 0f, 1f);
    }

    utils.revealShow(mFabBackground, true);

    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setDuration(600);
    searchViewLayout.setVisibility(View.VISIBLE);
    animator.start();
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {

            searchViewEditText.requestFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(searchViewEditText, InputMethodManager.SHOW_IMPLICIT);
            isSearchViewEnabled = true;
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });

}

From source file:foam.starwisp.StarwispBuilder.java

public void Update(final StarwispActivity ctx, final String ctxname, JSONArray arr) {

    String type = "";
    Integer tid = 0;/* www  .  j  a  va  2s .c o  m*/
    String token = "";

    try {

        type = arr.getString(0);
        tid = arr.getInt(1);
        token = arr.getString(2);

    } catch (JSONException e) {
        Log.e("starwisp",
                "Error parsing update arguments for " + ctxname + " " + arr.toString() + e.toString());
    }

    final Integer id = tid;

    //Log.i("starwisp", "Update: "+type+" "+id+" "+token);

    try {

        // non widget commands
        if (token.equals("toast")) {
            Toast msg = Toast.makeText(ctx.getBaseContext(), arr.getString(3), Toast.LENGTH_SHORT);
            LinearLayout linearLayout = (LinearLayout) msg.getView();
            View child = linearLayout.getChildAt(0);
            TextView messageTextView = (TextView) child;
            messageTextView.setTextSize(arr.getInt(4));
            msg.show();
            return;
        }

        if (token.equals("play-sound")) {
            String name = arr.getString(3);

            if (name.equals("ping")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.ping);
                mp.start();
            }
            if (name.equals("active")) {
                MediaPlayer mp = MediaPlayer.create(ctx, R.raw.active);
                mp.start();
            }
        }

        if (token.equals("soundfile-start-recording")) {
            String filename = arr.getString(3);
            m_SoundManager.StartRecording(filename);
        }
        if (token.equals("soundfile-stop-recording")) {
            m_SoundManager.StopRecording();
        }
        if (token.equals("soundfile-start-playback")) {
            String filename = arr.getString(3);
            m_SoundManager.StartPlaying(filename);
        }
        if (token.equals("soundfile-stop-playback")) {
            m_SoundManager.StopPlaying();
        }

        if (token.equals("vibrate")) {
            Vibrator v = (Vibrator) ctx.getSystemService(Context.VIBRATOR_SERVICE);
            v.vibrate(arr.getInt(3));
        }

        if (type.equals("replace-fragment")) {
            int ID = arr.getInt(1);
            String name = arr.getString(2);
            Fragment fragment = ActivityManager.GetFragment(name);
            FragmentTransaction ft = ctx.getSupportFragmentManager().beginTransaction();

            ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

            //ft.setCustomAnimations(  R.animator.fragment_slide_left_enter,
            //             R.animator.fragment_slide_right_exit);

            //ft.setCustomAnimations(
            //    R.animator.card_flip_right_in, R.animator.card_flip_right_out,
            //    R.animator.card_flip_left_in, R.animator.card_flip_left_out);
            ft.replace(ID, fragment);
            ft.addToBackStack(null);
            ft.commit();
            return;
        }

        if (token.equals("dialog-fragment")) {
            FragmentManager fm = ctx.getSupportFragmentManager();
            final int ID = arr.getInt(3);
            final JSONArray lp = arr.getJSONArray(4);
            final String name = arr.getString(5);

            final Dialog dialog = new Dialog(ctx);
            dialog.setTitle("Title...");

            LinearLayout inner = new LinearLayout(ctx);
            inner.setId(ID);
            inner.setLayoutParams(BuildLayoutParams(lp));

            dialog.setContentView(inner);

            //                Fragment fragment = ActivityManager.GetFragment(name);
            //                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
            //                fragmentTransaction.add(ID,fragment);
            //                fragmentTransaction.commit();

            dialog.show();

            /*                DialogFragment df = new DialogFragment() {
            @Override
            public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                     Bundle savedInstanceState) {
                LinearLayout inner = new LinearLayout(ctx);
                inner.setId(ID);
                inner.setLayoutParams(BuildLayoutParams(lp));
                    
                return inner;
            }
                    
            @Override
            public Dialog onCreateDialog(Bundle savedInstanceState) {
                Dialog ret = super.onCreateDialog(savedInstanceState);
                Log.i("starwisp","MAKINGDAMNFRAGMENT");
                    
                Fragment fragment = ActivityManager.GetFragment(name);
                FragmentTransaction fragmentTransaction = ctx.getSupportFragmentManager().beginTransaction();
                fragmentTransaction.add(1,fragment);
                fragmentTransaction.commit();
                return ret;
            }
                            };
                            df.show(ctx.getFragmentManager(), "foo");
            */
        }

        if (token.equals("time-picker-dialog")) {

            final Calendar c = Calendar.getInstance();
            int hour = c.get(Calendar.HOUR_OF_DAY);
            int minute = c.get(Calendar.MINUTE);

            // Create a new instance of TimePickerDialog and return it
            TimePickerDialog d = new TimePickerDialog(ctx, null, hour, minute, true);
            d.show();
            return;
        }
        ;

        if (token.equals("view")) {
            //ctx.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse()));

            File f = new File(arr.getString(3));
            Uri fileUri = Uri.fromFile(f);

            Intent myIntent = new Intent(android.content.Intent.ACTION_VIEW);
            String extension = android.webkit.MimeTypeMap.getFileExtensionFromUrl(arr.getString(3));
            String mimetype = android.webkit.MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
            myIntent.setDataAndType(fileUri, mimetype);
            ctx.startActivity(myIntent);
            return;
        }

        if (token.equals("make-directory")) {
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(3));
            file.mkdirs();
            return;
        }

        if (token.equals("list-files")) {
            final String name = arr.getString(3);
            File file = new File(((StarwispActivity) ctx).m_AppDir + arr.getString(5));
            // todo, should probably call callback with empty list
            if (file != null) {
                File list[] = file.listFiles();

                if (list != null) {
                    String code = "(";
                    for (int i = 0; i < list.length; i++) {
                        code += " \"" + list[i].getName() + "\"";
                    }
                    code += ")";

                    DialogCallback(ctx, ctxname, name, code);
                }
            }
            return;
        }

        if (token.equals("gps-start")) {
            final String name = arr.getString(3);

            if (m_LocationManager == null) {
                m_LocationManager = (LocationManager) ctx.getSystemService(Context.LOCATION_SERVICE);
                m_GPS = new DorisLocationListener(m_LocationManager);
            }

            m_GPS.Start((StarwispActivity) ctx, name, this, arr.getInt(5), arr.getInt(6));
            return;
        }

        if (token.equals("sensors-get")) {
            final String name = arr.getString(3);
            if (m_SensorHandler == null) {
                m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this);
            }
            m_SensorHandler.GetSensors((StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("sensors-start")) {
            final String name = arr.getString(3);
            final JSONArray requested_json = arr.getJSONArray(5);
            ArrayList<Integer> requested = new ArrayList<Integer>();

            try {
                for (int i = 0; i < requested_json.length(); i++) {
                    requested.add(requested_json.getInt(i));
                }
            } catch (JSONException e) {
                Log.e("starwisp", "Error parsing data in sensors start " + e.toString());
            }

            // start it up...
            if (m_SensorHandler == null) {
                m_SensorHandler = new SensorHandler((StarwispActivity) ctx, this);
            }
            m_SensorHandler.StartSensors((StarwispActivity) ctx, name, this, requested);
            return;
        }

        if (token.equals("sensors-stop")) {
            if (m_SensorHandler != null) {
                m_SensorHandler.StopSensors();
            }
            return;
        }

        if (token.equals("walk-draggable")) {
            final String name = arr.getString(3);
            int iid = arr.getInt(5);
            DialogCallback(ctx, ctxname, name, WalkDraggable(ctx, name, ctxname, iid).replace("\\", ""));
            return;
        }

        if (token.equals("delayed")) {
            final String name = arr.getString(3);
            final int d = arr.getInt(5);
            Runnable timerThread = new Runnable() {
                public void run() {
                    DialogCallback(ctx, ctxname, name, "");
                }
            };
            m_Handler.removeCallbacksAndMessages(null);
            m_Handler.postDelayed(timerThread, d);
            return;
        }

        if (token.equals("network-connect")) {
            final String name = arr.getString(3);
            final String ssid = arr.getString(5);
            m_NetworkManager.Start(ssid, (StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("http-request")) {
            Log.i("starwisp", "http-request called");
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "normal", "", name);
            }
            return;
        }

        if (token.equals("http-post")) {
            Log.i("starwisp", "http-post called");
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http request");
                final String name = arr.getString(3);
                final String url = arr.getString(5);
                final String data = arr.getString(6);
                m_NetworkManager.StartRequestThread(url, "post", data, name);
            }
            return;
        }

        if (token.equals("http-upload")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http ul request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "upload", "", filename);
            }
            return;
        }

        if (token.equals("http-download")) {
            if (m_NetworkManager.state == NetworkManager.State.CONNECTED) {
                Log.i("starwisp", "attempting http dl request");
                final String filename = arr.getString(4);
                final String url = arr.getString(5);
                m_NetworkManager.StartRequestThread(url, "download", "", filename);
            }
            return;
        }

        if (token.equals("take-photo")) {
            photo(ctx, arr.getString(3), arr.getInt(4));
        }

        if (token.equals("bluetooth")) {
            final String name = arr.getString(3);
            m_Bluetooth.Start((StarwispActivity) ctx, name, this);
            return;
        }

        if (token.equals("bluetooth-send")) {
            m_Bluetooth.Write(arr.getString(3));
        }

        if (token.equals("process-image-in-place")) {
            BitmapCache.ProcessInPlace(arr.getString(3));
        }

        if (token.equals("send-mail")) {
            final String to[] = new String[1];
            to[0] = arr.getString(3);
            final String subject = arr.getString(4);
            final String body = arr.getString(5);

            JSONArray attach = arr.getJSONArray(6);
            ArrayList<String> paths = new ArrayList<String>();
            for (int a = 0; a < attach.length(); a++) {
                Log.i("starwisp", attach.getString(a));
                paths.add(attach.getString(a));
            }

            email(ctx, to[0], "", subject, body, paths);
        }

        if (token.equals("date-picker-dialog")) {
            final Calendar c = Calendar.getInstance();
            int day = c.get(Calendar.DAY_OF_MONTH);
            int month = c.get(Calendar.MONTH);
            int year = c.get(Calendar.YEAR);

            final String name = arr.getString(3);

            // Create a new instance of TimePickerDialog and return it
            DatePickerDialog d = new DatePickerDialog(ctx, new DatePickerDialog.OnDateSetListener() {
                public void onDateSet(DatePicker view, int year, int month, int day) {
                    DialogCallback(ctx, ctxname, name, day + " " + month + " " + year);
                }
            }, year, month, day);
            d.show();
            return;
        }
        ;

        if (token.equals("alert-dialog")) {
            final String name = arr.getString(3);
            final String msg = arr.getString(5);
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Yes", dialogClickListener)
                    .setNegativeButton("No", dialogClickListener).show();
            return;
        }

        if (token.equals("ok-dialog")) {
            final String name = arr.getString(3);
            final String msg = arr.getString(5);
            DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int result = 0;
                    if (which == DialogInterface.BUTTON_POSITIVE)
                        result = 1;
                    DialogCallback(ctx, ctxname, name, "" + result);
                }
            };
            AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
            builder.setMessage(msg).setPositiveButton("Ok", dialogClickListener).show();
            return;
        }

        if (token.equals("start-activity")) {
            ActivityManager.StartActivity(ctx, arr.getString(3), arr.getInt(4), arr.getString(5));
            return;
        }

        if (token.equals("start-activity-goto")) {
            ActivityManager.StartActivityGoto(ctx, arr.getString(3), arr.getString(4));
            return;
        }

        if (token.equals("finish-activity")) {
            ctx.setResult(arr.getInt(3));
            ctx.finish();
            return;
        }

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

        if (id == 0) {
            Log.i("starwisp", "Zero ID, aborting...");
            return;
        }

        // now try and find the widget
        final View vv = ctx.findViewById(id);
        if (vv == null) {
            Log.i("starwisp", "Can't find widget : " + id);
            return;
        }

        // tokens that work on everything
        if (token.equals("hide")) {
            vv.setVisibility(View.GONE);
            return;
        }

        if (token.equals("show")) {
            vv.setVisibility(View.VISIBLE);
            return;
        }

        // only tested on spinners
        if (token.equals("disabled")) {
            vv.setAlpha(0.3f);
            //vv.getSelectedView().setEnabled(false);
            vv.setEnabled(false);
            return;
        }

        if (token.equals("enabled")) {
            vv.setAlpha(1.0f);
            //vv.getSelectedView().setEnabled(true);
            vv.setEnabled(true);
            return;
        }

        if (token.equals("animate")) {
            JSONArray trans = arr.getJSONArray(3);

            final TranslateAnimation animation = new TranslateAnimation(getPixelsFromDp(ctx, trans.getInt(0)),
                    getPixelsFromDp(ctx, trans.getInt(1)), getPixelsFromDp(ctx, trans.getInt(2)),
                    getPixelsFromDp(ctx, trans.getInt(3)));
            animation.setDuration(1000);
            animation.setFillAfter(false);
            animation.setInterpolator(new AnticipateOvershootInterpolator(1.0f));
            animation.setAnimationListener(new AnimationListener() {
                @Override
                public void onAnimationEnd(Animation animation) {
                    vv.clearAnimation();
                    Log.i("starwisp", "animation end");
                    ((ViewManager) vv.getParent()).removeView(vv);

                    //LayoutParams lp = new LayoutParams(imageView.getWidth(), imageView.getHeight());
                    //lp.setMargins(50, 100, 0, 0);
                    //imageView.setLayoutParams(lp);
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationStart(Animation animation) {
                    Log.i("starwisp", "animation start");
                }

            });

            vv.startAnimation(animation);
            return;
        }

        // tokens that work on everything
        if (token.equals("set-enabled")) {
            Log.i("starwisp", "set-enabled called...");
            vv.setEnabled(arr.getInt(3) == 1);
            vv.setClickable(arr.getInt(3) == 1);
            if (vv.getBackground() != null) {
                if (arr.getInt(3) == 0) {
                    //vv.setBackgroundColor(0x00000000);
                    vv.getBackground().setColorFilter(0x20000000, PorterDuff.Mode.MULTIPLY);
                } else {
                    vv.getBackground().setColorFilter(null);
                }
            }
            return;
        }

        if (token.equals("background-colour")) {
            JSONArray col = arr.getJSONArray(3);

            if (type.equals("linear-layout")) {
                vv.setBackgroundColor(Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)));
            } else {
                //vv.setBackgroundColor();
                vv.getBackground().setColorFilter(
                        Color.argb(col.getInt(3), col.getInt(0), col.getInt(1), col.getInt(2)),
                        PorterDuff.Mode.MULTIPLY);
            }
            vv.invalidate();
            return;
        }

        // special cases

        if (type.equals("linear-layout")) {
            //Log.i("starwisp","linear-layout update id: "+id);
            StarwispLinearLayout.Update(this, (LinearLayout) vv, token, ctx, ctxname, arr);
            return;
        }

        if (type.equals("relative-layout")) {
            StarwispRelativeLayout.Update(this, (RelativeLayout) vv, token, ctx, ctxname, arr);
            return;
        }

        if (type.equals("draggable")) {
            LinearLayout v = (LinearLayout) vv;
            if (token.equals("contents")) {
                v.removeAllViews();
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }

            if (token.equals("contents-add")) {
                JSONArray children = arr.getJSONArray(3);
                for (int i = 0; i < children.length(); i++) {
                    Build(ctx, ctxname, new JSONArray(children.getString(i)), v);
                }
            }
        }

        if (type.equals("button-grid")) {
            LinearLayout horiz = (LinearLayout) vv;

            if (token.equals("grid-buttons")) {
                horiz.removeAllViews();

                JSONArray params = arr.getJSONArray(3);
                String buttontype = params.getString(0);
                int height = params.getInt(1);
                int textsize = params.getInt(2);
                LayoutParams lp = BuildLayoutParams(params.getJSONArray(3));
                final JSONArray buttons = params.getJSONArray(4);
                final int count = buttons.length();
                int vertcount = 0;
                LinearLayout vert = null;

                for (int i = 0; i < count; i++) {
                    JSONArray button = buttons.getJSONArray(i);

                    if (vertcount == 0) {
                        vert = new LinearLayout(ctx);
                        vert.setId(0);
                        vert.setOrientation(LinearLayout.VERTICAL);
                        horiz.addView(vert);
                    }
                    vertcount = (vertcount + 1) % height;

                    if (buttontype.equals("button")) {
                        Button b = new Button(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("toggle")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                String arg = "#f";
                                if (((ToggleButton) v).isChecked())
                                    arg = "#t";
                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " " + arg);
                            }
                        });
                        vert.addView(b);
                    } else if (buttontype.equals("single")) {
                        ToggleButton b = new ToggleButton(ctx);
                        b.setId(button.getInt(0));
                        b.setText(button.getString(1));
                        b.setTextSize(textsize);
                        b.setLayoutParams(lp);
                        b.setTypeface(((StarwispActivity) ctx).m_Typeface);
                        final String fn = params.getString(5);
                        b.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
                                try {
                                    for (int i = 0; i < count; i++) {
                                        JSONArray button = buttons.getJSONArray(i);
                                        int bid = button.getInt(0);
                                        if (bid != v.getId()) {
                                            ToggleButton tb = (ToggleButton) ctx.findViewById(bid);
                                            tb.setChecked(false);
                                        }
                                    }
                                } catch (JSONException e) {
                                    Log.e("starwisp", "Error parsing on click data " + e.toString());
                                }

                                CallbackArgs(ctx, ctxname, id, "" + v.getId() + " #t");
                            }
                        });
                        vert.addView(b);
                    }

                }
            }
        }

        /*
                    if (type.equals("grid-layout")) {
        GridLayout v = (GridLayout)vv;
        if (token.equals("contents")) {
            v.removeAllViews();
            JSONArray children = arr.getJSONArray(3);
            for (int i=0; i<children.length(); i++) {
                Build(ctx,ctxname,new JSONArray(children.getString(i)), v);
            }
        }
                    }
        */
        if (type.equals("view-pager")) {
            ViewPager v = (ViewPager) vv;
            if (token.equals("switch")) {
                v.setCurrentItem(arr.getInt(3));
            }
            if (token.equals("pages")) {
                final JSONArray items = arr.getJSONArray(3);
                v.setAdapter(new FragmentPagerAdapter(ctx.getSupportFragmentManager()) {
                    @Override
                    public int getCount() {
                        return items.length();
                    }

                    @Override
                    public Fragment getItem(int position) {
                        try {
                            String fragname = items.getString(position);
                            return ActivityManager.GetFragment(fragname);
                        } catch (JSONException e) {
                            Log.e("starwisp", "Error parsing pages data " + e.toString());
                        }
                        return null;
                    }
                });
            }
        }

        if (type.equals("image-view")) {
            ImageView v = (ImageView) vv;
            if (token.equals("image")) {
                int iid = ctx.getResources().getIdentifier(arr.getString(3), "drawable", ctx.getPackageName());
                v.setImageResource(iid);
            }
            if (token.equals("external-image")) {
                v.setImageBitmap(BitmapCache.Load(arr.getString(3)));
            }
            return;
        }

        if (type.equals("text-view") || type.equals("debug-text-view")) {
            TextView v = (TextView) vv;
            if (token.equals("text")) {
                if (type.equals("debug-text-view")) {
                    //v.setMovementMethod(new ScrollingMovementMethod());
                }
                v.setText(Html.fromHtml(arr.getString(3)), BufferType.SPANNABLE);
                //                    v.invalidate();
            }
            if (token.equals("file")) {
                v.setText(LoadData(arr.getString(3)));
            }

            return;
        }

        if (type.equals("edit-text")) {
            EditText v = (EditText) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }
            if (token.equals("request-focus")) {
                v.requestFocus();
                InputMethodManager imm = (InputMethodManager) ctx
                        .getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(v, InputMethodManager.SHOW_IMPLICIT);
            }
            return;
        }

        if (type.equals("button")) {
            Button v = (Button) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("toggle-button")) {
            ToggleButton v = (ToggleButton) vv;
            if (token.equals("text")) {
                v.setText(arr.getString(3));
                return;
            }

            if (token.equals("checked")) {
                if (arr.getInt(3) == 0)
                    v.setChecked(false);
                else
                    v.setChecked(true);
                return;
            }

            if (token.equals("listener")) {
                final String fn = arr.getString(3);
                v.setOnClickListener(new View.OnClickListener() {
                    public void onClick(View v) {
                        m_Scheme.eval("(" + fn + ")");
                    }
                });
            }
            return;
        }

        if (type.equals("canvas")) {
            StarwispCanvas v = (StarwispCanvas) vv;
            if (token.equals("drawlist")) {
                v.SetDrawList(arr.getJSONArray(3));
            }
            return;
        }

        if (type.equals("camera-preview")) {
            final CameraPreview v = (CameraPreview) vv;

            if (token.equals("take-picture")) {
                final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3);

                v.TakePicture(new PictureCallback() {
                    public void onPictureTaken(byte[] input, Camera camera) {
                        Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length);
                        Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true);
                        ByteArrayOutputStream blob = new ByteArrayOutputStream();
                        resized.compress(Bitmap.CompressFormat.JPEG, 100, blob);

                        String datetime = getDateTime();
                        String filename = path + datetime + ".jpg";
                        SaveData(filename, blob.toByteArray());
                        v.Shutdown();
                        ctx.finish();
                    }
                });
            }

            // don't shut the activity down and use provided path
            if (token.equals("take-picture-cont")) {
                final String path = ((StarwispActivity) ctx).m_AppDir + arr.getString(3);

                Log.i("starwisp", "take-picture-cont fired");

                v.TakePicture(new PictureCallback() {
                    public void onPictureTaken(byte[] input, Camera camera) {
                        Log.i("starwisp", "on picture taken...");

                        // the version used by the uav app

                        Bitmap original = BitmapFactory.decodeByteArray(input, 0, input.length);
                        //Bitmap resized = Bitmap.createScaledBitmap(original, PHOTO_WIDTH, PHOTO_HEIGHT, true);
                        ByteArrayOutputStream blob = new ByteArrayOutputStream();
                        original.compress(Bitmap.CompressFormat.JPEG, 95, blob);
                        original.recycle();
                        String filename = path;
                        Log.i("starwisp", path);
                        SaveData(filename, blob.toByteArray());

                        // burn gps into exif data
                        if (m_GPS.currentLocation != null) {
                            double latitude = m_GPS.currentLocation.getLatitude();
                            double longitude = m_GPS.currentLocation.getLongitude();

                            try {
                                ExifInterface exif = new ExifInterface(filename);
                                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE, GPS.convert(latitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LATITUDE_REF,
                                        GPS.latitudeRef(latitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE, GPS.convert(longitude));
                                exif.setAttribute(ExifInterface.TAG_GPS_LONGITUDE_REF,
                                        GPS.longitudeRef(longitude));
                                exif.saveAttributes();
                            } catch (IOException e) {
                                Log.i("starwisp",
                                        "Couldn't open " + filename + " to add exif data: ioexception caught.");
                            }

                        }

                        v.TakenPicture();
                    }
                });
            }

            if (token.equals("shutdown")) {
                v.Shutdown();
            }

            return;
        }

        if (type.equals("seek-bar")) {
            SeekBar v = new SeekBar(ctx);
            if (token.equals("max")) {
                // android seekbar bug workaround
                int p = v.getProgress();
                v.setMax(0);
                v.setProgress(0);
                v.setMax(arr.getInt(3));
                v.setProgress(1000);

                // not working.... :(
            }
        }

        if (type.equals("spinner")) {
            Spinner v = (Spinner) vv;

            if (token.equals("selection")) {
                v.setSelection(arr.getInt(3));
            }

            if (token.equals("array")) {
                final JSONArray items = arr.getJSONArray(3);
                ArrayList<String> spinnerArray = new ArrayList<String>();

                for (int i = 0; i < items.length(); i++) {
                    spinnerArray.add(items.getString(i));
                }

                ArrayAdapter spinnerArrayAdapter = new ArrayAdapter<String>(ctx, R.layout.spinner_item,
                        spinnerArray) {
                    public View getView(int position, View convertView, ViewGroup parent) {
                        View v = super.getView(position, convertView, parent);
                        ((TextView) v).setTypeface(((StarwispActivity) ctx).m_Typeface);
                        return v;
                    }
                };

                spinnerArrayAdapter.setDropDownViewResource(R.layout.spinner_layout);
                v.setAdapter(spinnerArrayAdapter);

                final int wid = id;
                // need to update for new values
                v.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                    public void onItemSelected(AdapterView<?> a, View v, int pos, long id) {
                        CallbackArgs(ctx, ctxname, wid, "" + pos);
                    }

                    public void onNothingSelected(AdapterView<?> v) {
                    }
                });

            }
            return;
        }

        if (type.equals("draw-map")) {
            DrawableMap v = m_DMaps.get(id);
            if (v != null) {
                if (token.equals("polygons")) {
                    v.UpdateFromJSON(arr.getJSONArray(3));
                }
                if (token.equals("centre")) {
                    JSONArray tokens = arr.getJSONArray(3);
                    v.Centre(tokens.getDouble(0), tokens.getDouble(1), tokens.getInt(2));
                }
                if (token.equals("layout")) {
                    v.m_parent.setLayoutParams(BuildLayoutParams(arr.getJSONArray(3)));
                }
            } else {
                Log.e("starwisp", "Asked to update a drawmap which doesn't exist");
            }
        }

    } catch (JSONException e) {
        Log.e("starwisp", "Error parsing builder data " + e.toString());
        Log.e("starwisp", "type:" + type + " id:" + id + " token:" + token);
    }
}

From source file:com.barbrdo.app.activities.UserProfileActivity.java

@Override
public void onSuccessRedirection(int taskID) {
    InputMethodManager imm;
    switch (taskID) {
    case Constants.TaskID.SHOP_BARBERS:
        utilObj.stopLoader();//from  ww w . j ava2  s. c o m
        if (appInstance.shopDetail != null)
            setData();
        break;

    case Constants.TaskID.PROFILE_PICTURE:
        utilObj.stopLoader();
        if (appInstance.accountUpdate != null) {
            appInstance.userDetail.user = appInstance.accountUpdate.user;
            sessionManager.saveUser(appInstance.userDetail);

            if (!TextUtils.isEmpty(appInstance.userDetail.user.picture)) {
                imageLoader.displayImage(sessionManager.getImageBaseUrl() + appInstance.userDetail.user.picture,
                        imageViewProfilePicture, options);
            }
        }
        break;

    case Constants.TaskID.ACCOUNT:
        isEdit = false;
        invalidateOptionsMenu();
        editTextPhone.setEnabled(false);
        editTextFirstName.setEnabled(false);
        editTextLastName.setEnabled(false);
        editTextPassword.setEnabled(false);
        editTextConfirmPassword.setEnabled(false);
        textViewSearchRadius.setEnabled(false);
        editTextBio.setEnabled(false);
        textViewMemberSince.setEnabled(false);
        editTextPassword.setText("");
        editTextConfirmPassword.setText("");
        getView(R.id.cv_password_change).setVisibility(View.GONE);
        if (appInstance.accountUpdate != null) {
            utilObj.showToast(mContext, appInstance.message, 2);
            appInstance.userDetail.user = appInstance.accountUpdate.user;
            sessionManager.saveUser(appInstance.userDetail);

            String fullName = "";
            if (!TextUtils.isEmpty(appInstance.userDetail.user.firstName))
                fullName = appInstance.userDetail.user.firstName;
            if (!TextUtils.isEmpty(appInstance.userDetail.user.firstName)
                    && !TextUtils.isEmpty(appInstance.userDetail.user.lastName))
                fullName = appInstance.userDetail.user.firstName + " " + appInstance.userDetail.user.lastName;
            textViewUsername.setText(fullName);
        }
        if (user.userType.equalsIgnoreCase(getString(R.string.shop_))) {
            updateShop();
            return;
        }
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editTextFirstName, InputMethodManager.HIDE_IMPLICIT_ONLY);
        utilObj.stopLoader();
        break;

    case Constants.TaskID.USER_PROFILE:
        utilObj.stopLoader();
        setData();
        break;

    case Constants.TaskID.UPDATE_SHOP:
        utilObj.stopLoader();
        editTextShopName.setEnabled(false);
        editTextAddress.setEnabled(false);
        editTextCity.setEnabled(false);
        editTextState.setEnabled(false);
        editTextZip.setEnabled(false);
        imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
        imm.showSoftInput(editTextFirstName, InputMethodManager.HIDE_IMPLICIT_ONLY);
        break;
    }
}

From source file:com.amaze.carbonfilemanager.activities.MainActivity.java

/**
 * show search view with a circular reveal animation
 *//*from w  ww.  j  av  a  2 s  .com*/
void revealSearchView() {
    final int START_RADIUS = 16;
    int endRadius = Math.max(toolbar.getWidth(), toolbar.getHeight());

    Animator animator;
    if (SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
        animator = ViewAnimationUtils.createCircularReveal(searchViewLayout, searchCoords[0] + 32,
                searchCoords[1] - 16, START_RADIUS, endRadius);
    } else {
        // TODO:ViewAnimationUtils.createCircularReveal
        animator = ObjectAnimator.ofFloat(searchViewLayout, "alpha", 0f, 1f);
    }

    utils.revealShow(fabBgView, true);

    animator.setInterpolator(new AccelerateDecelerateInterpolator());
    animator.setDuration(600);
    searchViewLayout.setVisibility(View.VISIBLE);
    animator.start();
    animator.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            searchViewEditText.requestFocus();
            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.showSoftInput(searchViewEditText, InputMethodManager.SHOW_IMPLICIT);
            isSearchViewEnabled = true;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void hideEaseButtons() {
    switchVisibility(mEase1Layout, View.GONE);
    switchVisibility(mEase2Layout, View.GONE);
    switchVisibility(mEase3Layout, View.GONE);
    switchVisibility(mEase4Layout, View.GONE);

    if (mFlipCardLayout.getVisibility() != View.VISIBLE) {
        switchVisibility(mFlipCardLayout, View.VISIBLE);
        mFlipCardLayout.requestFocus();//from w w w  .  ja  v a2s .  c om
    } else if (typeAnswer()) {
        mAnswerField.requestFocus();

        // Show soft keyboard
        InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                Context.INPUT_METHOD_SERVICE);
        inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
    }
}

From source file:com.ichi2.anki2.Reviewer.java

private void displayCardQuestion() {
    // show timer, if activated in the deck's preferences
    initTimer();//from  w  w  w .j  a  v a  2  s  . c  o m

    sDisplayAnswer = false;

    if (mButtonHeight == 0 && mRelativeButtonSize != 100) {
        mButtonHeight = mFlipCard.getHeight() * mRelativeButtonSize / 100;
        mFlipCard.setHeight(mButtonHeight);
        mEase1.setHeight(mButtonHeight);
        mEase2.setHeight(mButtonHeight);
        mEase3.setHeight(mButtonHeight);
        mEase4.setHeight(mButtonHeight);
    }

    setInterface();

    String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
    question = typeAnsQuestionFilter(question);

    if (mPrefFixArabic) {
        question = ArabicUtilities.reshapeSentence(question, true);
    }

    Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(question);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        // If the user wants to write the answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.VISIBLE);

            // Show soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
        }

        displayString = enrichWithQADiv(question, false);

        if (mSpeakText) {
            // ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
            // mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
        }

        if (mPrefRecord) {
            Recorder.reset();
            // check for auto record
            try {
                if (mSched.getCol().getDecks().confForDid(mCurrentCard.getDid()).getBoolean("autoRecord")) {
                    Recorder.startRecording();
                }
            } catch (JSONException e) {
                throw new RuntimeException(e);
            }
        }

    }

    updateCard(displayString);
    hideEaseButtons();

    // If the user want to show answer automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowAnswerTask);
        mTimeoutHandler.postDelayed(mShowAnswerTask, mWaitAnswerSecond * 1000);
    }
}

From source file:com.hichinaschool.flashcards.anki.Reviewer.java

private void displayCardQuestion() {
    // show timer, if activated in the deck's preferences
    initTimer();/*  w w w . ja va  2 s . c o m*/

    sDisplayAnswer = false;

    if (mButtonHeight == 0 && mRelativeButtonSize != 100) {
        mButtonHeight = mFlipCard.getHeight() * mRelativeButtonSize / 100;
        mFlipCard.setHeight(mButtonHeight);
        mEase1.setHeight(mButtonHeight);
        mEase2.setHeight(mButtonHeight);
        mEase3.setHeight(mButtonHeight);
        mEase4.setHeight(mButtonHeight);
    }

    setInterface();

    String question = mCurrentCard.getQuestion(mCurrentSimpleInterface);
    question = typeAnsQuestionFilter(question);

    if (mPrefFixArabic) {
        question = ArabicUtilities.reshapeSentence(question, true);
    }

    // Log.i(AnkiDroidApp.TAG, "question: '" + question + "'");

    String displayString = "";

    if (mCurrentSimpleInterface) {
        mCardContent = convertToSimple(question);
        if (mCardContent.length() == 0) {
            SpannableString hint = new SpannableString(
                    getResources().getString(R.string.simple_interface_hint, R.string.card_details_question));
            hint.setSpan(new StyleSpan(Typeface.ITALIC), 0, mCardContent.length(),
                    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            mCardContent = hint;
        }
    } else {
        // If the user wants to write the answer
        if (typeAnswer()) {
            mAnswerField.setVisibility(View.VISIBLE);

            // Show soft keyboard
            InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(
                    Context.INPUT_METHOD_SERVICE);
            inputMethodManager.showSoftInput(mAnswerField, InputMethodManager.SHOW_FORCED);
        }

        displayString = enrichWithQADiv(question, false);

        if (mSpeakText) {
            // ReadText.setLanguageInformation(Model.getModel(DeckManager.getMainDeck(),
            // mCurrentCard.getCardModelId(), false).getId(), mCurrentCard.getCardModelId());
        }
    }

    updateCard(displayString);
    hideEaseButtons();

    // If the user want to show answer automatically
    if (mPrefUseTimer) {
        mTimeoutHandler.removeCallbacks(mShowAnswerTask);
        mTimeoutHandler.postDelayed(mShowAnswerTask, mWaitAnswerSecond * 1000);
    }
}

From source file:im.neon.activity.VectorRoomActivity.java

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

    if (CommonActivityUtils.shouldRestartApp(this)) {
        Log.e(LOG_TAG, "onCreate : Restart the application.");
        CommonActivityUtils.restartApp(this);
        return;//  w  ww.j  a v a 2  s . c o m
    }

    final Intent intent = getIntent();
    if (!intent.hasExtra(EXTRA_ROOM_ID)) {
        Log.e(LOG_TAG, "No room ID extra.");
        finish();
        return;
    }

    mSession = MXCActionBarActivity.getSession(this, intent);

    if (mSession == null) {
        Log.e(LOG_TAG, "No MXSession.");
        finish();
        return;
    }

    String roomId = intent.getStringExtra(EXTRA_ROOM_ID);

    // ensure that the preview mode is really expected
    if (!intent.hasExtra(EXTRA_ROOM_PREVIEW_ID)) {
        sRoomPreviewData = null;
        Matrix.getInstance(this).clearTmpStoresList();
    }

    if (CommonActivityUtils.isGoingToSplash(this, mSession.getMyUserId(), roomId)) {
        Log.d(LOG_TAG, "onCreate : Going to splash screen");
        return;
    }

    //setDragEdge(SwipeBackLayout.DragEdge.LEFT);

    // bind the widgets of the room header view. The room header view is displayed by
    // clicking on the title of the action bar
    mRoomHeaderView = (RelativeLayout) findViewById(R.id.action_bar_header);
    mActionBarHeaderRoomTopic = (TextView) findViewById(R.id.action_bar_header_room_topic);
    mActionBarHeaderRoomName = (TextView) findViewById(R.id.action_bar_header_room_title);
    mActionBarHeaderActiveMembers = (TextView) findViewById(R.id.action_bar_header_room_members);
    mActionBarHeaderRoomAvatar = (ImageView) mRoomHeaderView.findViewById(R.id.avatar_img);
    mActionBarHeaderInviteMemberView = mRoomHeaderView.findViewById(R.id.action_bar_header_invite_members);
    mRoomPreviewLayout = findViewById(R.id.room_preview_info_layout);
    mVectorPendingCallView = (VectorPendingCallView) findViewById(R.id.room_pending_call_view);
    mVectorOngoingConferenceCallView = (VectorOngoingConferenceCallView) findViewById(
            R.id.room_ongoing_conference_call_view);
    mE2eImageView = (ImageView) findViewById(R.id.room_encrypted_image_view);

    // hide the header room as soon as the bottom layout (text edit zone) is touched
    findViewById(R.id.room_bottom_layout).setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
            return false;
        }
    });

    // use a toolbar instead of the actionbar
    // to be able to display an expandable header
    mToolbar = (android.support.v7.widget.Toolbar) findViewById(R.id.room_toolbar);
    this.setSupportActionBar(mToolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    // set the default custom action bar layout,
    // that will be displayed from the custom action bar layout
    setActionBarDefaultCustomLayout();

    mCallId = intent.getStringExtra(EXTRA_START_CALL_ID);
    mEventId = intent.getStringExtra(EXTRA_EVENT_ID);
    mDefaultRoomName = intent.getStringExtra(EXTRA_DEFAULT_NAME);
    mDefaultTopic = intent.getStringExtra(EXTRA_DEFAULT_TOPIC);

    // the user has tapped on the "View" notification button
    if ((null != intent.getAction()) && (intent.getAction().startsWith(NotificationUtils.TAP_TO_VIEW_ACTION))) {
        // remove any pending notifications
        NotificationManager notificationsManager = (NotificationManager) this
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationsManager.cancelAll();
    }

    Log.d(LOG_TAG, "Displaying " + roomId);

    mEditText = (EditText) findViewById(R.id.editText_messageBox);

    // hide the header room as soon as the message input text area is touched
    mEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            enableActionBarHeader(HIDE_ACTION_BAR_HEADER);
        }
    });

    // IME's DONE button is treated as a send action
    mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) {
            int imeActionId = actionId & EditorInfo.IME_MASK_ACTION;

            if (EditorInfo.IME_ACTION_DONE == imeActionId) {
                sendTextMessage();
            }

            return false;
        }
    });

    mSendingMessagesLayout = findViewById(R.id.room_sending_message_layout);
    mSendImageView = (ImageView) findViewById(R.id.room_send_image_view);
    mSendButtonLayout = findViewById(R.id.room_send_layout);
    mSendButtonLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (!TextUtils.isEmpty(mEditText.getText())) {
                sendTextMessage();
            } else {
                // hide the header room
                enableActionBarHeader(HIDE_ACTION_BAR_HEADER);

                FragmentManager fm = getSupportFragmentManager();
                IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                        .findFragmentByTag(TAG_FRAGMENT_ATTACHMENTS_DIALOG);

                if (fragment != null) {
                    fragment.dismissAllowingStateLoss();
                }

                final Integer[] messages = new Integer[] { R.string.option_send_files,
                        R.string.option_take_photo_video, };

                final Integer[] icons = new Integer[] { R.drawable.ic_material_file, // R.string.option_send_files
                        R.drawable.ic_material_camera, // R.string.option_take_photo
                };

                fragment = IconAndTextDialogFragment.newInstance(icons, messages, null,
                        ContextCompat.getColor(VectorRoomActivity.this, R.color.vector_text_black_color));
                fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                    @Override
                    public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                        Integer selectedVal = messages[position];

                        if (selectedVal == R.string.option_send_files) {
                            VectorRoomActivity.this.launchFileSelectionIntent();
                        } else if (selectedVal == R.string.option_take_photo_video) {
                            if (CommonActivityUtils.checkPermissions(
                                    CommonActivityUtils.REQUEST_CODE_PERMISSION_TAKE_PHOTO,
                                    VectorRoomActivity.this)) {
                                launchCamera();
                            }
                        }
                    }
                });

                fragment.show(fm, TAG_FRAGMENT_ATTACHMENTS_DIALOG);
            }
        }
    });

    mEditText.addTextChangedListener(new TextWatcher() {
        @Override
        public void afterTextChanged(android.text.Editable s) {
            if (null != mRoom) {
                MXLatestChatMessageCache latestChatMessageCache = VectorRoomActivity.this.mLatestChatMessageCache;
                String textInPlace = latestChatMessageCache.getLatestText(VectorRoomActivity.this,
                        mRoom.getRoomId());

                // check if there is really an update
                // avoid useless updates (initializations..)
                if (!mIgnoreTextUpdate && !textInPlace.equals(mEditText.getText().toString())) {
                    latestChatMessageCache.updateLatestMessage(VectorRoomActivity.this, mRoom.getRoomId(),
                            mEditText.getText().toString());
                    handleTypingNotification(mEditText.getText().length() != 0);
                }

                manageSendMoreButtons();
                refreshCallButtons();
            }
        }

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

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

    mVectorPendingCallView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = VectorCallViewActivity.getActiveCall();
            if (null != call) {
                final Intent intent = new Intent(VectorRoomActivity.this, VectorCallViewActivity.class);
                intent.putExtra(VectorCallViewActivity.EXTRA_MATRIX_ID,
                        call.getSession().getCredentials().userId);
                intent.putExtra(VectorCallViewActivity.EXTRA_CALL_ID, call.getCallId());

                VectorRoomActivity.this.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        VectorRoomActivity.this.startActivity(intent);
                    }
                });
            } else {
                // if the call is no more active, just remove the view
                mVectorPendingCallView.onCallTerminated();
            }
        }
    });

    mActionBarHeaderInviteMemberView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchRoomDetails(VectorRoomDetailsActivity.PEOPLE_TAB_INDEX);
        }
    });

    // notifications area
    mNotificationsArea = findViewById(R.id.room_notifications_area);
    mNotificationIconImageView = (ImageView) mNotificationsArea.findViewById(R.id.room_notification_icon);
    mNotificationTextView = (TextView) mNotificationsArea.findViewById(R.id.room_notification_message);

    mCanNotPostTextView = findViewById(R.id.room_cannot_post_textview);

    // increase the clickable area to open the keyboard.
    // when there is no text, it is quite small and some user thought the edition was disabled.
    findViewById(R.id.room_sending_message_layout).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (mEditText.requestFocus()) {
                InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
                imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
            }
        }
    });

    mStartCallLayout = findViewById(R.id.room_start_call_layout);
    mStartCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if ((null != mRoom) && mRoom.isEncrypted() && (mRoom.getActiveMembers().size() > 2)) {
                // display the dialog with the info text
                AlertDialog.Builder permissionsInfoDialog = new AlertDialog.Builder(VectorRoomActivity.this);
                Resources resource = getResources();
                permissionsInfoDialog
                        .setMessage(resource.getString(R.string.room_no_conference_call_in_encrypted_rooms));
                permissionsInfoDialog.setIcon(android.R.drawable.ic_dialog_alert);
                permissionsInfoDialog.setPositiveButton(resource.getString(R.string.ok), null);
                permissionsInfoDialog.show();

            } else if (isUserAllowedToStartConfCall()) {
                displayVideoCallIpDialog();
            } else {
                displayConfCallNotAllowed();
            }
        }
    });

    mStopCallLayout = findViewById(R.id.room_end_call_layout);
    mStopCallLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            IMXCall call = mSession.mCallsManager.getCallWithRoomId(mRoom.getRoomId());

            if (null != call) {
                call.hangup(null);
            }
        }
    });

    findViewById(R.id.room_button_margin_right).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // extend the right side of right button
            // to avoid clicking in the void
            if (mStopCallLayout.getVisibility() == View.VISIBLE) {
                mStopCallLayout.performClick();
            } else if (mStartCallLayout.getVisibility() == View.VISIBLE) {
                mStartCallLayout.performClick();
            } else if (mSendButtonLayout.getVisibility() == View.VISIBLE) {
                mSendButtonLayout.performClick();
            }
        }
    });

    mMyUserId = mSession.getCredentials().userId;

    CommonActivityUtils.resumeEventStream(this);

    mRoom = mSession.getDataHandler().getRoom(roomId, false);

    FragmentManager fm = getSupportFragmentManager();
    mVectorMessageListFragment = (VectorMessageListFragment) fm
            .findFragmentByTag(TAG_FRAGMENT_MATRIX_MESSAGE_LIST);

    if (mVectorMessageListFragment == null) {
        Log.d(LOG_TAG, "Create VectorMessageListFragment");

        // this fragment displays messages and handles all message logic
        mVectorMessageListFragment = VectorMessageListFragment.newInstance(mMyUserId, roomId, mEventId,
                (null == sRoomPreviewData) ? null : VectorMessageListFragment.PREVIEW_MODE_READ_ONLY,
                org.matrix.androidsdk.R.layout.fragment_matrix_message_list_fragment);
        fm.beginTransaction().add(R.id.anchor_fragment_messages, mVectorMessageListFragment,
                TAG_FRAGMENT_MATRIX_MESSAGE_LIST).commit();
    } else {
        Log.d(LOG_TAG, "Reuse VectorMessageListFragment");
    }

    mVectorRoomMediasSender = new VectorRoomMediasSender(this, mVectorMessageListFragment,
            Matrix.getInstance(this).getMediasCache());
    mVectorRoomMediasSender.onRestoreInstanceState(savedInstanceState);

    manageRoomPreview();

    addRoomHeaderClickListeners();

    // in timeline mode (i.e search in the forward and backward room history)
    // or in room preview mode
    // the edition items are not displayed
    if (!TextUtils.isEmpty(mEventId) || (null != sRoomPreviewData)) {
        mNotificationsArea.setVisibility(View.GONE);
        findViewById(R.id.bottom_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notification_separator).setVisibility(View.GONE);
        findViewById(R.id.room_notifications_area).setVisibility(View.GONE);

        View v = findViewById(R.id.room_bottom_layout);
        ViewGroup.LayoutParams params = v.getLayoutParams();
        params.height = 0;
        v.setLayoutParams(params);
    }

    mLatestChatMessageCache = Matrix.getInstance(this).getDefaultLatestChatMessageCache();

    // some medias must be sent while opening the chat
    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        final Intent mediaIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);

        // sanity check
        if (null != mediaIntent) {
            mEditText.postDelayed(new Runnable() {
                @Override
                public void run() {
                    intent.removeExtra(EXTRA_ROOM_INTENT);
                    sendMediasIntent(mediaIntent);
                }
            }, 1000);
        }
    }

    mVectorOngoingConferenceCallView.initRoomInfo(mSession, mRoom);
    mVectorOngoingConferenceCallView
            .setCallClickListener(new VectorOngoingConferenceCallView.ICallClickListener() {

                private void startCall(boolean isVideo) {
                    if (CommonActivityUtils.checkPermissions(
                            isVideo ? CommonActivityUtils.REQUEST_CODE_PERMISSION_VIDEO_IP_CALL
                                    : CommonActivityUtils.REQUEST_CODE_PERMISSION_AUDIO_IP_CALL,
                            VectorRoomActivity.this)) {
                        startIpCall(isVideo);
                    }
                }

                @Override
                public void onVoiceCallClick() {
                    startCall(false);
                }

                @Override
                public void onVideoCallClick() {
                    startCall(true);
                }
            });

    View avatarLayout = findViewById(R.id.room_self_avatar);

    if (null != avatarLayout) {
        mAvatarImageView = (ImageView) avatarLayout.findViewById(R.id.avatar_img);
    }

    refreshSelfAvatar();

    // in case a "Send as" dialog was in progress when the activity was destroyed (life cycle)
    mVectorRoomMediasSender.resumeResizeMediaAndSend();

    // header visibility has launched
    enableActionBarHeader(intent.getBooleanExtra(EXTRA_EXPAND_ROOM_HEADER, false) ? SHOW_ACTION_BAR_HEADER
            : HIDE_ACTION_BAR_HEADER);

    // the both flags are only used once
    intent.removeExtra(EXTRA_EXPAND_ROOM_HEADER);

    Log.d(LOG_TAG, "End of create");
}