Example usage for android.app ActionBar setLogo

List of usage examples for android.app ActionBar setLogo

Introduction

In this page you can find the example usage for android.app ActionBar setLogo.

Prototype

public abstract void setLogo(Drawable logo);

Source Link

Document

Set the logo to display in the 'home' section of the action bar.

Usage

From source file:activities.PaintingActivity.java

public void restoreActionBar() {
    ActionBar actionBar = getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setDisplayShowTitleEnabled(false);
    actionBar.setDisplayUseLogoEnabled(true);
    actionBar.setLogo(R.drawable.navbar_logo);
    actionBar.setIcon(R.drawable.ic_drawer);
}

From source file:org.jorge.lolin1.ui.activities.ChatRoomActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ActionBar actionBar = getActionBar();
    friendName = null;/* w w  w . j ava2  s.c  o  m*/
    if (actionBar != null) {
        actionBar.setDisplayHomeAsUpEnabled(Boolean.TRUE);
        actionBar.setTitle(friendName = getIntent().getStringExtra(ChatOverviewActivity.KEY_FRIEND_NAME));
        try {
            actionBar
                    .setLogo(
                            Drawable.createFromPath(
                                    ProfileCacheableBitmapLoader
                                            .getPathByID(getApplicationContext(),
                                                    FriendManager.getInstance().findFriendByName(friendName)
                                                            .getStatus().getProfileIconId())
                                            .getAbsolutePath()));
        } catch (NullPointerException ex) {
            startActivity(new Intent(getApplicationContext(), ChatOverviewActivity.class));//Clicking notification with app closed
            finish();
            return;
        }
        actionBar.setDisplayUseLogoEnabled(Boolean.TRUE);
    }
    ChatNotificationManager.dismissNotifications(getApplicationContext(), friendName);
    setContentView(R.layout.activity_chat_room);

    final EditText messageContentsTextField = (EditText) findViewById(android.R.id.inputArea);

    messageContentsTextField.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId != EditorInfo.IME_ACTION_DONE)
                return Boolean.FALSE;
            String contents = messageContentsTextField.getText().toString();
            if (TextUtils.isEmpty(contents))
                return Boolean.TRUE;
            adapter.add(new ChatMessageWrapper(contents, System.currentTimeMillis()));
            sendMessage(contents, friendName);
            messageContentsTextField.setText("");
            messageContentsTextField.requestFocus();
            return Boolean.TRUE;
        }

        private void sendMessage(String contents, String friendName) {
            new AsyncTask<String, Void, Void>() {
                @Override
                protected Void doInBackground(String... params) {
                    Friend target;
                    ChatMessageWrapper messageWrapper = new ChatMessageWrapper(params[0],
                            System.currentTimeMillis());
                    logString("debug", "Sending message " + params[0] + " to " + params[1]);
                    ChatBundleManager.addMessageToFriendChat(messageWrapper,
                            target = FriendManager.getInstance().findFriendByName(params[1]));
                    scrollListViewToBottom();
                    target.sendMessage(params[0]);
                    return null;
                }
            }.executeOnExecutor(Executors.newSingleThreadExecutor(), contents, friendName);
        }
    });

    conversationListView = (ListView) findViewById(android.R.id.list);
    conversationListView.setChoiceMode(AbsListView.CHOICE_MODE_NONE);

    logString("debug", "Calling adapter constructor");
    adapter = new ChatRoomAdapter(getApplicationContext(),
            FriendManager.getInstance().findFriendByName(friendName));

    if (!TextUtils.isEmpty(friendName))
        conversationListView.setAdapter(adapter);

    scrollListViewToBottom();

    registerLocalBroadcastReceiver();
    scrollListViewToBottom();
}

From source file:com.sastra.app.timetable.TimetableActivity.java

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

    Log.d(TAG, "Entered On Create");

    ActionBar Bar = getActionBar();
    Bar.setLogo(R.drawable.ic_launcher_1);
    //Bar.setTitle("");
    // String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "/Android/data/SASTRA Timetable/files/test.txt";

    SharedPreferences mPreferences = this.getSharedPreferences("AB", MODE_PRIVATE);

    boolean firstTime = mPreferences.getBoolean("firstTime", true);
    if (firstTime) {

        SharedPreferences.Editor editor = mPreferences.edit();
        editor.putBoolean("firstTime", false);
        editor.commit();/*from w w w. ja v  a2  s  . c  om*/
        Dialog d2 = new Dialog(this);
        d2.setTitle("HELP");
        d2.setCanceledOnTouchOutside(true);
        TextView tv = new TextView(this);
        tv.setText(
                "This application can be used to store your timetable.First,click on Manage Subjects Icon(Wrench Icon) inorder to add all your subjects.Click on Add Subjects on top and enter the details of your subject.The fields that appear are optional and not manditory.Once you have added all the subjects,go back to the main screen and click on Add Classes icon(Plus Icon) to add the different classes to your timetable.The fields that appear are again optional and all of them need not be filled.You can long press on any particular subject to edit or delete them.You can delete all the informations using Delete All(Garbage Icon) option.");
        ScrollView sav = new ScrollView(this);
        sav.addView(tv);
        LayoutParams lap = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
        d2.addContentView(sav, lap);
        d2.show();
    }

    boolean enabled = true;

    Bar.setHomeButtonEnabled(enabled);

    //File database=getApplicationContext().getDatabasePath("massey.db");
    // if (database.exists()) {
    data = new InternalDB(this);
    // }

    // add fragments
    mFragments = new ArrayList<Fragment>();

    mFragments.add(Fragment.instantiate(this, MONDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, TUESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, WEDNESDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, THURSDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, FRIDAYFRAGMENT));
    mFragments.add(Fragment.instantiate(this, SATURDAYFRAGMENT));

    // adapter
    mAdapter = new MainPagerAdapter(getSupportFragmentManager(), mFragments);

    // pager
    mPager = (ViewPager) findViewById(R.id.view_pager);

    mPager.setAdapter(mAdapter);

    // indicator
    mIndicator = (TitlePageIndicator) findViewById(R.id.title_indicator);

    //mIndicator.setBackgroundColor(0x0106000e);
    //mIndicator.setFooterColor(0xffffff);
    mIndicator.setTextColor(0xFF000000);
    mIndicator.setSelectedColor(0xFF000000);
    mIndicator.setViewPager(mPager);

    intent = new Intent(getApplicationContext(), AddSubjects.class);//intent = new Intent(getApplicationContext(), AddSubjects.class);

    builder = new AlertDialog.Builder(this);
    builder.setMessage("Are you sure you want to delete all lessons?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteAllHours();
                    data.close();
                    // update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert = builder.create();

    builder2 = new AlertDialog.Builder(this);
    builder2.setMessage("Are you sure you want to delete this lesson?").setCancelable(false)
            .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    data.open();
                    data.deleteHour(OLDSName, OLDHDay, OLDHType, OLDHClass, OLDHStart, OLDHEnd);
                    data.close();
                    //update();
                    mAdapter.notifyDataSetChanged();
                    mAdapter.finishUpdate(mPager);
                }
            }).setNegativeButton("No", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int id) {
                    dialog.cancel();
                }
            });
    alert2 = builder2.create();

    //added

    addDialog = new Dialog(this);
    addDialog.setCancelable(false);
    action = "insert";
    addDialog.setTitle("Add Class");
    addDialog.setContentView(R.layout.timetable_addhour);

    HType = (EditText) addDialog.findViewById(R.id.typeEdit);
    HClass = (EditText) addDialog.findViewById(R.id.classroomEdit);
    arraydays = new String[] { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
    HDay = (Spinner) addDialog.findViewById(R.id.day);
    arrayadapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, arraydays);
    arrayadapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    HDay.setAdapter(arrayadapter);
    HDay.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedDay = arraydays[position];
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    fromDialog = new TimePickerDialog(this, fromTimeSetListener, 12, 0, true);
    toDialog = new TimePickerDialog(this, toTimeSetListener, 12, 0, true);

    //This place is important.

    SName = (Spinner) addDialog.findViewById(R.id.SName);
    SName.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1, int position, long id) {
            selectedSubject = (String) arraySubjects[position];
            Log.d("AB", "We are inside the setOnItemSelectedListener for Sname : 264");
            Log.d("AB", selectedSubject);
        }

        public void onNothingSelected(AdapterView<?> arg0) {
            // TODO Auto-generated method stub
        }
    });

    Button buttonFrom = (Button) addDialog.findViewById(R.id.buttonFrom);
    buttonFrom.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            fromDialog.show();
        }
    });

    Button buttonTo = (Button) addDialog.findViewById(R.id.buttonTo);
    buttonTo.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            toDialog.show();
        }
    });

    start = (TextView) addDialog.findViewById(R.id.start);
    end = (TextView) addDialog.findViewById(R.id.end);

    Button cancel = (Button) addDialog.findViewById(R.id.cancel);
    cancel.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
        }

    });

    Button ok = (Button) addDialog.findViewById(R.id.ok);
    ok.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {
            int HDay = SDay2IDay(selectedDay);
            if (action.equals("insert")) {
                data.open();
                data.insertIntoHours(selectedSubject, HDay, HType.getText().toString(),
                        HClass.getText().toString(), start.getText().toString(), end.getText().toString());
                data.close();
            } else if (action.equals("edit")) {
                data.open();
                data.updateHours(OLDSName, OLDHType, OLDHClass, OLDHDay, OLDHStart, OLDHEnd, selectedSubject,
                        HDay, HType.getText().toString(), HClass.getText().toString(),
                        start.getText().toString(), end.getText().toString());
                data.close();
            }
            addDialog.cancel();
            fromDialog.updateTime(12, 0);
            toDialog.updateTime(12, 0);
            start.setText("--:--");
            end.setText("--:--");
            HType.setText(null);
            HClass.setText(null);
            mAdapter.notifyDataSetChanged();
            //update();
            mAdapter.finishUpdate(mPager);
        }
    });

}

From source file:com.example.office.ui.Office365DemoActivity.java

/**
 * Choose one of the available screens to display (via appropriate Fragment).
 *
 * @param newScreen Screen to be shown.//from w w w.ja  v a 2  s. co  m
 */
private void switchScreen(UI.Screen newScreen) {
    try {
        ActionBar actionBar = getActionBar();

        mDrawerList.setItemChecked(newScreen.ordinal(), true);
        setTitle(newScreen.getName(this));
        actionBar.setLogo(newScreen.getIcon(this));

        if (newScreen.in(ScreenGroup.MAIL)) {
            Screen currentScreen = Screen.getByTag(mCurrentFragmentTag, this);
            if (!currentScreen.in(ScreenGroup.MAIL)) {
                Fragment newFragment;
                FragmentManager fragmentManager = getFragmentManager();
                FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
                switch (newScreen) {
                case CONTACTS:
                    newFragment = new ContactsFragment();
                    break;
                case MAILBOX:
                    newFragment = new DraftsFragment();
                    break;
                case CALENDAR: {
                    newFragment = new CalendarFragment();
                    break;
                }
                default: {
                    newFragment = new DraftsFragment();
                    break;
                }
                }
                fragmentTransaction.add(R.id.content_pane, newFragment, newScreen.getName(this));
                fragmentTransaction.commit();
            }
            actionBar.selectTab(actionBar.getTabAt(newScreen.ordinal()));
            mCurrentFragmentTag = newScreen.getName(this);
        }
        mDrawerLayout.closeDrawer(mDrawerList);
    } catch (Exception e) {
        Logger.logApplicationException(e, getClass().getSimpleName() + ".switchBox(): Error.");
    }
}

From source file:com.example.office.ui.Office365DemoActivity.java

/**
 * Initializes activity UI elements./*from  w  w  w .j  av  a  2s.  c  om*/
 */
private void initUi() {
    if (!mIsInitialized) {
        setContentView(R.layout.main_activity);

        mTitle = mDrawerTitle = getTitle();

        // Setting up Action Bar and Tabs.
        ActionBar actionBar = getActionBar();
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        actionBar.setDisplayShowTitleEnabled(true);
        actionBar.setLogo(R.drawable.ic_action_mail);

        Tab tab = actionBar.newTab().setText(UI.Screen.CONTACTS.getName(this))
                .setTag(UI.Screen.CONTACTS.getName(this)).setTabListener(new TabListener<ContactsFragment>(this,
                        UI.Screen.CONTACTS.getName(this), ContactsFragment.class));
        actionBar.addTab(tab);

        tab = actionBar.newTab().setText(UI.Screen.MAILBOX.getName(this))
                .setTag(UI.Screen.MAILBOX.getName(this)).setTabListener(new TabListener<DraftsFragment>(this,
                        UI.Screen.MAILBOX.getName(this), DraftsFragment.class));
        actionBar.addTab(tab, true);

        tab = actionBar.newTab().setText(UI.Screen.CALENDAR.getName(this))
                .setTag(UI.Screen.CALENDAR.getName(this)).setTabListener(new TabListener<CalendarFragment>(this,
                        UI.Screen.CALENDAR.getName(this), CalendarFragment.class));
        actionBar.addTab(tab);

        // Setting up sliding drawer.
        mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        mDrawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
        mDrawerList = (ListView) findViewById(R.id.left_drawer);

        SlidingDrawerAdapter drawerAdapter = new SlidingDrawerAdapter(OfficeApplication.getContext(),
                R.layout.drawer_list_item, R.layout.drawer_delimiter);
        mDrawerList.setAdapter(drawerAdapter);

        mDrawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                try {
                    Screen[] drawerScreens = ScreenGroup.DRAWER.getMembers().toArray(new Screen[0]);
                    Screen currentScreen = DEFAULT_SCREEN;

                    // use id instead of position here because some positions used by delimiters, id contains real index of clicked item
                    if (drawerScreens != null && drawerScreens.length - 1 >= id) {
                        currentScreen = drawerScreens[(int) id];
                    }
                    switchScreen(currentScreen);
                } catch (Exception e) {
                    Logger.logApplicationException(e, getClass().getSimpleName() + "onItemClick(): Error.");
                }
            }
        });

        actionBar.setHomeButtonEnabled(true);

        // ActionBarDrawerToggle ties together the the proper interactions
        // between the sliding drawer and the action bar app icon
        mDrawerToggle = new ActionBarDrawerToggle(this,
                /* host Activity */mDrawerLayout, /* DrawerLayout object */
                R.drawable.ic_drawer, /* drawer navigation image replacing '<' */
                R.string.drawer_open, R.string.drawer_close) {
            public void onDrawerClosed(View view) {
                getActionBar().setTitle(mTitle);
                invalidateOptionsMenu();
            }

            public void onDrawerOpened(View drawerView) {
                getActionBar().setTitle(mDrawerTitle);
                invalidateOptionsMenu();
            }
        };
        mDrawerLayout.setDrawerListener(mDrawerToggle);
        mIsInitialized = true;
    }

    if (mSavedFragmentTag == null) {
        switchScreen(DEFAULT_SCREEN);
    } else {
        // This is not used mostly as we're going back to this activity when it
        // is at the top of the back stack. So (as it does have 'singleTop' in parameters) it is
        // simply restored and onNewIntent() is called instead of onCreate().
        // So savedInstanceState will usually be null. This is added to anticipate other future use cases.
        switchScreen(Screen.getByTag(mSavedFragmentTag, this));
    }
}

From source file:com.juick.android.ThreadActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    JuickAdvancedApplication.maybeEnableAcceleration(this);
    JuickAdvancedApplication.setupTheme(this);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    //getSherlock().requestFeature(Window.FEATURE_NO_TITLE);
    final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
    super.onCreate(savedInstanceState);
    handler = new Handler();

    Intent i = getIntent();/*from  ww w .ja v a 2  s  .  c  om*/
    mid = (MessageID) i.getSerializableExtra("mid");
    if (mid == null) {
        finish();
    }

    messagesSource = (MessagesSource) i.getSerializableExtra("messagesSource");
    if (sp.getBoolean("fullScreenThread", false)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    setContentView(R.layout.thread);
    /*
            findViewById(R.id.gotoMain).setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        startActivity(new Intent(ThreadActivity.this, MainActivity.class));
    }
            });
    */
    final View buttons = findViewById(R.id.buttons);
    bSend = (ImageButton) findViewById(R.id.buttonSend);
    bSend.setOnClickListener(this);
    bAttach = (ImageButton) findViewById(R.id.buttonAttachment);
    bAttach.setOnClickListener(this);
    etMessage = (EditText) findViewById(R.id.editMessage);

    if (sp.getBoolean("helvNueFonts", false)) {
        etMessage.setTypeface(JuickAdvancedApplication.helvNue);
        /*
                    TextView oldTitle = (TextView)findViewById(R.id.old_title);
                    oldTitle.setTypeface(JuickAdvancedApplication.helvNue);
        */
    }

    Button cancel = (Button) findViewById(R.id.buttonCancel);
    cancel.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            doCancel();
        }
    });

    tvReplyTo = (TextView) findViewById(R.id.textReplyTo);
    replyToContainer = (RelativeLayout) findViewById(R.id.replyToContainer);
    setHeight(replyToContainer, 0);
    showThread = (Button) findViewById(R.id.showThread);
    draftsButton = (Button) findViewById(R.id.drafts);
    etMessage.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (hasFocus) {
                etMessage.setHint("");
                setHeight(buttons, ActionBar.LayoutParams.WRAP_CONTENT);
                InputMethodManager inputMgr = (InputMethodManager) getSystemService(
                        Context.INPUT_METHOD_SERVICE);
                inputMgr.toggleSoftInput(0, 0);
            } else {
                etMessage.setHint(R.string.ClickToReply);
                setHeight(buttons, 0);
            }
            //To change body of implemented methods use File | Settings | File Templates.
        }
    });
    draftsButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            class Item {
                String label;
                long ts;
                int index;

                Item(String label, long ts, int index) {
                    this.label = label;
                    this.ts = ts;
                    this.index = index;
                }
            }
            final ArrayList<Item> items = new ArrayList<Item>();
            final SharedPreferences drafts = getSharedPreferences("drafts", MODE_PRIVATE);
            for (int q = 0; q < 1000; q++) {
                String msg = drafts.getString("message" + q, null);
                if (msg != null) {
                    if (msg.length() > 50)
                        msg = msg.substring(0, 50);
                    items.add(new Item(msg, drafts.getLong("timestamp" + q, 0), q));
                }
            }
            Collections.sort(items, new Comparator<Item>() {
                @Override
                public int compare(Item item, Item item2) {
                    final long l = item2.ts - item.ts;
                    return l == 0 ? 0 : l > 0 ? 1 : -1;
                }
            });
            CharSequence[] arr = new CharSequence[items.size()];
            for (int i1 = 0; i1 < items.size(); i1++) {
                Item item = items.get(i1);
                arr[i1] = item.label;
            }
            new AlertDialog.Builder(ThreadActivity.this).setItems(arr, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, final int which) {
                    final Runnable doPull = new Runnable() {
                        @Override
                        public void run() {
                            pullDraft(null, drafts, items.get(which).index);
                            updateDraftsButton();
                        }
                    };
                    if (pulledDraft != null
                            && pulledDraft.trim().equals(etMessage.getText().toString().trim())) {
                        // no need to ask, user just looks at the drafts
                        saveDraft(pulledDraftRid, pulledDraftMid, pulledDraftTs, pulledDraft);
                        doPull.run();
                    } else {
                        if (etMessage.getText().toString().length() > 0) {
                            new AlertDialog.Builder(ThreadActivity.this)
                                    .setTitle(getString(R.string.ReplacingText))
                                    .setMessage(getString(R.string.YourTextWillBeReplaced))
                                    .setNegativeButton(android.R.string.ok,
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    doPull.run();
                                                }

                                            })
                                    .setNeutralButton(
                                            getString(pulledDraft != null ? R.string.SaveChangedDraft
                                                    : R.string.SaveDraft),
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                    if (pulledDraft != null) {
                                                        saveDraft(pulledDraftRid, pulledDraftMid,
                                                                System.currentTimeMillis(),
                                                                etMessage.getText().toString());
                                                    } else {
                                                        saveDraft(rid, mid.toString(),
                                                                System.currentTimeMillis(),
                                                                etMessage.getText().toString());
                                                    }
                                                    doPull.run();
                                                }
                                            })
                                    .setPositiveButton(android.R.string.cancel,
                                            new DialogInterface.OnClickListener() {
                                                @Override
                                                public void onClick(DialogInterface dialog, int which) {
                                                }
                                            })
                                    .show();
                        } else {
                            doPull.run();
                        }
                    }
                }
            }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).show();
        }
    });
    enableDrafts = (sp.getBoolean("enableDrafts", false));
    if (sp.getBoolean("capitalizeReplies", false)) {
        etMessage.setInputType(etMessage.getInputType() | EditorInfo.TYPE_TEXT_FLAG_CAP_SENTENCES);
    }
    FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
    tf = new ThreadFragment();
    tf.init(getLastCustomNonConfigurationInstance(), this);
    Bundle args = new Bundle();
    args.putSerializable("mid", mid);
    args.putSerializable("messagesSource", messagesSource);
    args.putSerializable("prefetched", i.getSerializableExtra("prefetched"));
    args.putSerializable("originalMessage", i.getSerializableExtra("originalMessage"));
    args.putBoolean("scrollToBottom", i.getBooleanExtra("scrollToBottom", false));
    tf.setArguments(args);
    ft.add(R.id.threadfragment, tf);
    ft.commit();
    MainActivity.restyleChildrenOrWidget(getWindow().getDecorView());
    detector = new GestureDetector(this, new GestureDetector.OnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {
            return false;
        }

        @Override
        public void onShowPress(MotionEvent e) {

        }

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return false;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            return false;
        }

        @Override
        public void onLongPress(MotionEvent e) {

        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            if (velocityX > 0 && Math.abs(velocityX) > 4 * Math.abs(velocityY) && Math.abs(velocityX) > 400) {
                if (etMessage.getText().toString().trim().length() == 0) {
                    System.out.println("velocityX=" + velocityX + " velocityY" + velocityY);
                    if (sp.getBoolean("swipeToClose", true)) {
                        onBackPressed();
                    }
                }
            }
            return false;
        }
    });

    com.actionbarsherlock.app.ActionBar actionBar = getSherlock().getActionBar();
    actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_STANDARD);
    actionBar.setHomeButtonEnabled(true);
    actionBar.setLogo(R.drawable.back_button);

}

From source file:com.polychrom.cordova.ActionBarPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (!plugin_actions.contains(action)) {
        return false;
    }//from  w ww . j  a v a2  s . com

    final Activity ctx = (Activity) cordova;

    if ("isAvailable".equals(action)) {
        JSONObject result = new JSONObject();
        result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR));
        callbackContext.success(result);
        return true;
    }

    final ActionBar bar = ctx.getActionBar();
    if (bar == null) {
        Window window = ctx.getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            callbackContext
                    .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!");
        } else {
            callbackContext.error("Failed to get ActionBar");
        }

        return true;
    }

    if (menu == null) {
        callbackContext.error("Options menu not initialised");
        return true;
    }

    final StringBuffer error = new StringBuffer();
    JSONObject result = new JSONObject();

    if ("isShowing".equals(action)) {
        result.put("value", bar.isShowing());
    } else if ("getHeight".equals(action)) {
        result.put("value", bar.getHeight());
    } else if ("getDisplayOptions".equals(action)) {
        result.put("value", bar.getDisplayOptions());
    } else if ("getNavigationMode".equals(action)) {
        result.put("value", bar.getNavigationMode());
    } else if ("getSelectedNavigationItem".equals(action)) {
        result.put("value", bar.getSelectedNavigationIndex());
    } else if ("getSubtitle".equals(action)) {
        result.put("value", bar.getSubtitle());
    } else if ("getTitle".equals(action)) {
        result.put("value", bar.getTitle());
    } else {
        try {
            JSONException exception = new Runnable() {
                public JSONException exception = null;

                public void run() {
                    try {
                        // This is a bit of a hack (should be specific to the request, not global)
                        bases = new String[] { removeFilename(webView.getOriginalUrl()),
                                removeFilename(webView.getUrl()) };

                        if ("show".equals(action)) {
                            bar.show();
                        } else if ("hide".equals(action)) {
                            bar.hide();
                        } else if ("setMenu".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            menu_definition = args.getJSONArray(0);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                ctx.invalidateOptionsMenu();
                            }
                        } else if ("setTabs".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            bar.removeAllTabs();
                            tab_callbacks.clear();

                            if (!buildTabs(bar, args.getJSONArray(0))) {
                                error.append("Invalid tab bar definition");
                            }
                        } else if ("setDisplayHomeAsUpEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHomeAsUp can not be null");
                                return;
                            }

                            bar.setDisplayHomeAsUpEnabled(args.getBoolean(0));
                        } else if ("setDisplayOptions".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("options can not be null");
                                return;
                            }

                            final int options = args.getInt(0);
                            bar.setDisplayOptions(options);
                        } else if ("setDisplayShowHomeEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHome can not be null");
                                return;
                            }

                            bar.setDisplayShowHomeEnabled(args.getBoolean(0));
                        } else if ("setDisplayShowTitleEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showTitle can not be null");
                                return;
                            }

                            bar.setDisplayShowTitleEnabled(args.getBoolean(0));
                        } else if ("setDisplayUseLogoEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("useLogo can not be null");
                                return;
                            }

                            bar.setDisplayUseLogoEnabled(args.getBoolean(0));
                        } else if ("setHomeButtonEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("enabled can not be null");
                                return;
                            }

                            bar.setHomeButtonEnabled(args.getBoolean(0));
                        } else if ("setIcon".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("icon can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setIcon(drawable);
                        } else if ("setListNavigation".equals(action)) {
                            JSONArray items = null;
                            if (args.isNull(0) == false) {
                                items = args.getJSONArray(0);
                            }

                            navigation_adapter.setItems(items);
                            bar.setListNavigationCallbacks(navigation_adapter, navigation_listener);
                        } else if ("setLogo".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("logo can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setLogo(drawable);
                        } else if ("setNavigationMode".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("mode can not be null");
                                return;
                            }

                            final int mode = args.getInt(0);
                            bar.setNavigationMode(mode);
                        } else if ("setSelectedNavigationItem".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }

                            bar.setSelectedNavigationItem(args.getInt(0));
                        } else if ("setSubtitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("subtitle can not be null");
                                return;
                            }

                            bar.setSubtitle(args.getString(0));
                        } else if ("setTitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("title can not be null");
                                return;
                            }

                            bar.setTitle(args.getString(0));
                        }
                    } catch (JSONException e) {
                        exception = e;
                    } finally {
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }

                // Run task synchronously
                {
                    synchronized (this) {
                        ctx.runOnUiThread(this);
                        this.wait();
                    }
                }
            }.exception;

            if (exception != null) {
                throw exception;
            }
        } catch (InterruptedException e) {
            error.append("Function interrupted on UI thread");
        }
    }

    if (error.length() == 0) {
        if (result.length() > 0) {
            callbackContext.success(result);
        } else {
            callbackContext.success();
        }
    } else {
        callbackContext.error(error.toString());
    }

    return true;
}

From source file:com.native5.plugins.ActionBarPlugin.java

@Override
public boolean execute(final String action, final JSONArray args, final CallbackContext callbackContext)
        throws JSONException {
    if (!plugin_actions.contains(action)) {
        return false;
    }//from  w  w  w . j  a v a  2s  . c  om

    final Activity ctx = (Activity) cordova;

    if ("isAvailable".equals(action)) {
        JSONObject result = new JSONObject();
        result.put("value", ctx.getWindow().hasFeature(Window.FEATURE_ACTION_BAR));
        callbackContext.success(result);
        return true;
    }

    final ActionBar bar = ctx.getActionBar();
    if (bar == null) {
        Window window = ctx.getWindow();
        if (!window.hasFeature(Window.FEATURE_ACTION_BAR)) {
            callbackContext
                    .error("ActionBar feature not available, Window.FEATURE_ACTION_BAR must be enabled!");
        } else {
            callbackContext.error("Failed to get ActionBar");
        }

        return true;
    }

    if (menu == null) {
        callbackContext.error("Options menu not initialised");
        return true;
    }

    final StringBuffer error = new StringBuffer();
    JSONObject result = new JSONObject();

    if ("isShowing".equals(action)) {
        result.put("value", bar.isShowing());
    } else if ("getHeight".equals(action)) {
        result.put("value", bar.getHeight());
    } else if ("getDisplayOptions".equals(action)) {
        result.put("value", bar.getDisplayOptions());
    } else if ("getNavigationMode".equals(action)) {
        result.put("value", bar.getNavigationMode());
    } else if ("getSelectedNavigationItem".equals(action)) {
        result.put("value", bar.getSelectedNavigationIndex());
    } else if ("getSubtitle".equals(action)) {
        result.put("value", bar.getSubtitle());
    } else if ("getTitle".equals(action)) {
        result.put("value", bar.getTitle());
    } else {
        try {
            JSONException exception = new Runnable() {
                public JSONException exception = null;

                public void run() {
                    try {
                        // This is a bit of a hack (should be specific to the request, not global)
                        bases = new String[] { removeFilename(webView.getOriginalUrl()),
                                removeFilename(webView.getUrl()) };

                        if ("show".equals(action)) {
                            LOG.d("native5-action-bar", "Showing Action Bar");
                            bar.show();
                        } else if ("hide".equals(action)) {
                            bar.hide();
                        } else if ("setMenu".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            menu_definition = args.getJSONArray(0);

                            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
                                ctx.invalidateOptionsMenu();
                            }
                        } else if ("setTabs".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("menu can not be null");
                                return;
                            }

                            bar.removeAllTabs();
                            tab_callbacks.clear();

                            if (!buildTabs(bar, args.getJSONArray(0))) {
                                error.append("Invalid tab bar definition");
                            }
                        } else if ("setDisplayHomeAsUpEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHomeAsUp can not be null");
                                return;
                            }

                            bar.setDisplayHomeAsUpEnabled(args.getBoolean(0));
                        } else if ("setDisplayOptions".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("options can not be null");
                                return;
                            }

                            final int options = args.getInt(0);
                            bar.setDisplayOptions(options);
                        } else if ("setDisplayShowHomeEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showHome can not be null");
                                return;
                            }

                            bar.setDisplayShowHomeEnabled(args.getBoolean(0));
                        } else if ("setDisplayShowTitleEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("showTitle can not be null");
                                return;
                            }

                            bar.setDisplayShowTitleEnabled(args.getBoolean(0));
                        } else if ("setDisplayUseLogoEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("useLogo can not be null");
                                return;
                            }

                            bar.setDisplayUseLogoEnabled(args.getBoolean(0));
                        } else if ("setHomeButtonEnabled".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("enabled can not be null");
                                return;
                            }

                            bar.setHomeButtonEnabled(args.getBoolean(0));
                        } else if ("setIcon".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("icon can not be null");
                                return;
                            }

                            Drawable drawable = getDrawableForURI(args.getString(0));
                            bar.setIcon(drawable);
                        } else if ("setListNavigation".equals(action)) {
                            JSONArray items = null;
                            if (args.isNull(0) == false) {
                                items = args.getJSONArray(0);
                            }

                            navigation_adapter.setItems(items);
                            bar.setListNavigationCallbacks(navigation_adapter, navigation_listener);
                        } else if ("setLogo".equals(action)) {
                            String uri = args.getString(0);
                            if (args.isNull(0)) {
                                error.append("logo can not be null");
                                return;
                            }

                            //                        try {
                            //                           InputStream ims = ctx.getAssets().open(uri);
                            Drawable drawable = getDrawableForURI(uri);
                            //                                 Drawable.createFromStream(ims, null);
                            bar.setLogo(drawable);
                            bar.setBackgroundDrawable(getDrawableForURI("images/logo-bg.png"));
                            //                        } catch (IOException e) {
                            //                           e.printStackTrace();
                            //                        }
                        } else if ("setNavigationMode".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("mode can not be null");
                                return;
                            }

                            final int mode = args.getInt(0);
                            bar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
                        } else if ("setSelectedNavigationItem".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }
                            bar.setSelectedNavigationItem(args.getInt(0));
                        } else if ("setSelectedTab".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("position can not be null");
                                return;
                            }
                            LOG.d("setSelectedTab", bar.getTabCount() + "");
                            bar.selectTab(bar.getTabAt(args.getInt(0)));
                        } else if ("setSubtitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("subtitle can not be null");
                                return;
                            }

                            bar.setSubtitle(args.getString(0));
                        } else if ("setTitle".equals(action)) {
                            if (args.isNull(0)) {
                                error.append("title can not be null");
                                return;
                            }

                            bar.setTitle(args.getString(0));
                        }
                    } catch (JSONException e) {
                        exception = e;
                    } finally {
                        synchronized (this) {
                            this.notify();
                        }
                    }
                }

                // Run task synchronously
                {
                    synchronized (this) {
                        ctx.runOnUiThread(this);
                        this.wait();
                    }
                }
            }.exception;

            if (exception != null) {
                throw exception;
            }
        } catch (InterruptedException e) {
            error.append("Function interrupted on UI thread");
        }
    }

    if (error.length() == 0) {
        if (result.length() > 0) {
            callbackContext.success(result);
        } else {
            callbackContext.success();
        }
    } else {
        callbackContext.error(error.toString());
    }

    return true;
}