de.greenrobot.event.EventBus Java Examples

The following examples show how to use de.greenrobot.event.EventBus. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RumbleUnicastChannel.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void stopWorker() {
    if(!working)
        return;
    working = false;
    try {
        con.disconnect();
    } catch (LinkLayerConnectionException ignore) {
        //Log.d(TAG, "[-]"+ignore.getMessage());
    }
    finally {
        keepAlive.removeCallbacks(keepAliveFires);
        socketTimeout.removeCallbacks(socketTimeoutFires);
        if(EventBus.getDefault().isRegistered(this))
            EventBus.getDefault().unregister(this);
    }
}
 
Example #2
Source File: NewVersionAvailableEventTest.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
/**
 * Get the event bus that's being used in the app.
 *
 * @return The event bus.
 * @throws AssumptionViolatedException If the default event bus can't be constructed because of
 * the Android framework not being loaded. This will stop the calling tests from being reported
 * as failures.
 */
@NonNull
private static EventBus getEventBus() {
    try {
        return EventBus.getDefault();
    } catch (RuntimeException e) {
        /* The event bus uses the Looper from the Android framework, so
         * initializing it would throw a runtime exception if the
         * framework is not loaded. Nor can RoboGuice be used to inject
         * a mocked instance to get around this issue, since customizing
         * RoboGuice injections requires a Context.
         *
         * Robolectric can't be used to solve this issue, because it
         * doesn't support parameterized testing. The only solution that
         * could work at the moment would be to make this an
         * instrumented test suite.
         *
         * TODO: Mock the event bus when RoboGuice is replaced with
         * another dependency injection framework, or when there is a
         * Robolectric test runner available that support parameterized
         * tests.
         */
        throw new AssumptionViolatedException(
                "Event bus requires Android framework", e, nullValue());
    }
}
 
Example #3
Source File: MainActivity.java    From sctalk with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	logger.d("MainActivity#savedInstanceState:%s", savedInstanceState);
	//todo eric when crash, this will be called, why?
	if (savedInstanceState != null) {
		logger.w("MainActivity#crashed and restarted, just exit");
		jumpToLoginPage();
		finish();
	}

       // 在这个地方加可能会有问题吧
       EventBus.getDefault().register(this);
	imServiceConnector.connect(this);

	requestWindowFeature(Window.FEATURE_NO_TITLE);
	setContentView(R.layout.tt_activity_main);

	initTab();
	initFragment();
	setFragmentIndicator(0);
}
 
Example #4
Source File: WifiLinkLayerAdapter.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void linkStop() {
    if(!register)
        return;
    register = false;

    Log.d(TAG, "[-] Stopping Wifi");
    if(EventBus.getDefault().isRegistered(this))
        EventBus.getDefault().unregister(this);

    RumbleApplication.getContext().unregisterReceiver(mReceiver);
    linkDisconnected();

    wifiInf = null;
    wifiMan = null;
}
 
Example #5
Source File: PersonalInfoPresenter.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
    public void loadPersonalInfo() {
            String jid = personalInfoView.getJid();
            if (!TextUtils.isEmpty(jid)) {
                connectionUtil.getUserCard(jid, new IMLogicManager.NickCallBack() {
                    @Override
                    public void onNickCallBack(Nick nick) {
                        setPersonalInfo(nick);
                        if (personalInfoView != null) {
                            if(nick!=null&&!TextUtils.isEmpty(nick.getXmppId())){
                                //old
//                                ProfileUtils.displayGravatarByImageSrc(nick.getXmppId(),nick.getHeaderSrc(),personalInfoView.getImagetView());
                                //new
                                ProfileUtils.displayGravatarByImageSrc((Activity) personalInfoView.getContext(), nick.getHeaderSrc(), personalInfoView.getImagetView(), 0, 0);
                                EventBus.getDefault().post(
                                        new EventBusEvent.GravtarGot(nick.getHeaderSrc(), personalInfoView.getJid()));
                            }

//                            ProfileUtils.loadVCard4mNet(personalInfoView.getImagetView(), personalInfoView.getJid(), commentView, false);
                        }
                    }
                }, true, false);
            }
    }
 
Example #6
Source File: AuthorizeActivity.java    From Puff-Android with MIT License 6 votes vote down vote up
public void onEventMainThread(CryptoEvent event) {
    if (event.getField() == null ||!event.getField().equalsIgnoreCase("master")) {
        return;
    }
    if (event.getType() == AppConstants.TYPE_MASTER_OK) {
        dialog.dismiss();
        CryptoEvent result = new CryptoEvent(password, AppConstants.TYPE_MASTERPWD);
        EventBus.getDefault().post(result);
        this.setResult(RESULT_OK);
        finish();
    }
    if (event.getType() == AppConstants.TYPE_MASTER_NO) {
        mPasswordView.setError(getResources().getString(R.string.master_password_invalid));
        dialog.dismiss();
    }
    if (event.getType() == AppConstants.TYPE_SHTHPPN) {
        mPasswordView.setError(getResources().getString(R.string.master_password_invalid));
        dialog.dismiss();
    }


}
 
Example #7
Source File: OllieTester.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
public static void testAddressItems(Context context) {
	Delete.from(SimpleAddressItem.class).execute();

	final Collection<SimpleAddressItem> ollieModels =
			Generator.getAddresses(SimpleAddressItem.class, MainActivity.LOOP_COUNT);

	long startTime = System.currentTimeMillis();
	// Reuse method so we don't have to write
	TransactionManager.transact(Ollie.getDatabase(), new Runnable() {
		@Override
		public void run() {
			Saver.saveAll(ollieModels);
		}
	});
	EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.SAVE_TIME));

	startTime = System.currentTimeMillis();
	Collection<SimpleAddressItem> activeAndroidModelLoad =
			Select.from(SimpleAddressItem.class).fetch();
	EventBus.getDefault().post(new LogTestDataEvent(startTime, FRAMEWORK_NAME, MainActivity.LOAD_TIME));

	Delete.from(SimpleAddressItem.class).execute();
}
 
Example #8
Source File: NoteController.java    From nono-android with GNU General Public License v3.0 6 votes vote down vote up
public static long updateNoteLocal(final long sdfId, String groupName, final NoteDatabaseArray noteDatabaseArray, String oldUUid){
    noteDatabaseArray.uuid = oldUUid;
    final long newId;
    noteDatabaseArray.is_on_cloud = "false";
    newId = NoteDBHelper.getInstance().updateNote(sdfId,groupName,noteDatabaseArray);
    new Handler(Looper.getMainLooper()).post(new Runnable() {
        @Override
        public void run() {
            EventBus.getDefault().post(new NoteUpdateEvent(
                    newId,
                    noteDatabaseArray.content,
                    noteDatabaseArray,
                    sdfId,
                    noteDatabaseArray.uuid
            ));
        }
    });
    if(Looper.myLooper() == Looper.getMainLooper()){
        Toast.makeText(MyApp.getInstance().getApplicationContext(), "转储在本地喵~", Toast.LENGTH_SHORT).show();
    }
    return newId;
}
 
Example #9
Source File: CacheManager.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
public void onEventAsync(UserDeleteStatus event) {
    if(event.status == null)
        return;
    if(DatabaseFactory.getPushStatusDatabase(RumbleApplication.getContext()).deleteStatus(event.status.getUuid())) {
        if(event.status.hasAttachedFile()) {
            // if filename starts with a '/' it means that the file is from another album
            // we do not delete the file in that case
            if(!event.status.getFileName().startsWith("/")) {
                try {
                    File attached = new File(FileUtil.getWritableAlbumStorageDir(), event.status.getFileName());
                    if (attached.exists() && attached.isFile()) {
                        attached.delete();
                    }
                } catch (IOException e) {
                }
            }
        }
        EventBus.getDefault().post(new StatusDeletedEvent(event.status.getUuid(), event.status.getdbId()));
    }
}
 
Example #10
Source File: NeighbourManager.java    From Rumble with GNU General Public License v3.0 6 votes vote down vote up
public void onEvent(ScannerNeighbourTimeout event) {
    if(event.neighbour.isLocal())
        return;
    NeighbourDetail detail;
    synchronized (managerLock) {
        detail = neighborhood.get(event.neighbour);
        if (detail == null)
            return;
        if (!detail.channels.isEmpty())
            return;
        neighborhood.remove(event.neighbour);
    }
    EventBus.getDefault().post(new NeighbourUnreachable(event.neighbour,
            detail.reachable_time_nano, System.nanoTime()));
    EventBus.getDefault().post(new NeighborhoodChanged());
}
 
Example #11
Source File: PersonalInfoMyActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
@Override
public void setUpdateResult(final boolean result) {
    if (CommonConfig.isQtalk) {
        getHandler().post(new Runnable() {
            @Override
            public void run() {
                selGravatarPath = "";
                if (progressDialog != null && progressDialog.isShowing())
                    progressDialog.dismiss();
                if (result) {
                    personalInfoPresenter.loadGravatar(true);
                    EventBus.getDefault().post(new EventBusEvent.GravantarChanged());
                }
                Toast.makeText(PersonalInfoMyActivity.this, result ? getString(R.string.atom_ui_tip_gravantar_update_success) : getString(R.string.atom_ui_tip_gravantar_update_failure), Toast.LENGTH_LONG).show();
            }
        });
    }
}
 
Example #12
Source File: FileImportActivity.java    From secrecy with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    if (!EventBus.getDefault().isRegistered(this)) {
        EventBus.getDefault().register(this);
    }

    mToolbar = (Toolbar) findViewById(R.id.toolbar);

    setSupportActionBar(mToolbar);
    FileImportFragment fragment = new FileImportFragment();
    FragmentManager fragmentManager = getFragmentManager();
    fragmentManager.beginTransaction()
            .replace(R.id.drawer_layout, fragment, "mainactivitycontent")   //Replace the whole drawer layout
            .setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN)
            .commit();
}
 
Example #13
Source File: PbChatActivity.java    From imsdk-android with MIT License 6 votes vote down vote up
/**
     * 页面finish后释放相关资源
     */
    private void releaseResource() {
//        if (faceView != null) faceView.removeAllViews();
//        if (quickReplyLayout != null) quickReplyLayout.removeAllViews();
        if (pbChatViewAdapter != null) pbChatViewAdapter.releaseViews();
        if (mDialog != null && mDialog.isShowing()) {
            mDialog.dismiss();
        }
        getHandler().removeCallbacksAndMessages(null);
        if (encryptRequestCountTimer != null) encryptRequestCountTimer.cancel();
        if (chatingPresenter != null) {
            chatingPresenter.close();
        }
        if (waterMarkTextUtil != null) {
            waterMarkTextUtil.recyleBitmap();
        }
        EventBus.getDefault().unregister(handleChatEvent);
    }
 
Example #14
Source File: TinyBusPerformanceTest.java    From tinybus with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
	super.setUp();
	
	mTinyBus = new TinyBus();
	mEventBus = EventBus.builder()
			.eventInheritance(false)
			.sendNoSubscriberEvent(false).build();
	mOttoBus = new com.squareup.otto.Bus(new com.squareup.otto.ThreadEnforcer() {
		public void enforce(com.squareup.otto.Bus bus) {}
	});
	
	mSubscriber1 = new Subsriber1();
	mSubscriber2 = new Subsriber2();
	mSubscriber3 = new Subsriber3();
}
 
Example #15
Source File: MainActivity.java    From AndroidDatabaseLibraryComparison with MIT License 6 votes vote down vote up
/**
 * runs simple benchmarks (onClick from R.id.simple)
 * @param v button view
 */
public void runSimpleTrial(View v) {
    setBusyUI(true, getResources().getString(R.string.simple));
    resetChart();
    runTestThread = new Thread(new Runnable() {
        @Override
        public void run() {
            runningTests = true;
            Context applicationContext = MainActivity.this.getApplicationContext();
            OrmLiteTester.testAddressItems(applicationContext);
            GreenDaoTester.testAddressItems(applicationContext);
            DBFlowTester.testAddressItems(applicationContext);
            OllieTester.testAddressItems(applicationContext);
            RealmTester.testAddressItems(applicationContext);
            //SprinklesTester.testAddressItems(applicationContext);
            //AATester.testAddressItems(applicationContext);
            //SugarTester.testAddressItems(applicationContext);
            EventBus.getDefault().post(new TrialCompletedEvent(getResources().getString(R.string.simple)));
        }
    });
    runTestThread.start();
}
 
Example #16
Source File: PhoneCallReceiver.java    From SimplifyReader with Apache License 2.0 5 votes vote down vote up
@Override
public void onReceive(Context context, Intent intent) {
    if (null == intent) {
        return;
    }

    String action = intent.getAction();

    if (action.equals(Intent.ACTION_NEW_OUTGOING_CALL)) {
        EventBus.getDefault().post(new EventCenter(Constants.EVENT_STOP_PLAY_MUSIC));
    } else {
        final TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        telephonyManager.listen(new PhoneStateListener() {
            @Override
            public void onCallStateChanged(int state, String incomingNumber) {
                super.onCallStateChanged(state, incomingNumber);
                switch (state) {
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                    case TelephonyManager.CALL_STATE_RINGING:
                        EventBus.getDefault().post(new EventCenter(Constants.EVENT_STOP_PLAY_MUSIC));

                        break;

                    case TelephonyManager.CALL_STATE_IDLE:
                        EventBus.getDefault().post(new EventCenter(Constants.EVENT_START_PLAY_MUSIC));

                        break;
                }
            }
        }, PhoneStateListener.LISTEN_CALL_STATE);
    }
}
 
Example #17
Source File: PbChatActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.atom_ui_activity_chat);
        connectionUtil = ConnectionUtil.getInstance();
        waterMarkTextUtil = new WaterMarkTextUtil();
//        EventBus.getDefault().register(this);
        //bugly tag
//        CrashReportUtils.getInstance().setUserTag(55092);
        //处理一些额外的数据
        handleExtraData(savedInstanceState);
        //获取intent数据
        injectExtras(getIntent());

        //@消息管理
        mAtManager = new AtManager(this, jid);
        mAtManager.setTextChangeListener(this);
        //图片推荐
        new ImageDataSourceForRecommend(PbChatActivity.this, null, PbChatActivity.this);
        //初始化view
        bindViews();
        initViews();

        //处理收到加密会话
        if (!TextUtils.isEmpty(encryptBody)) {
            sendEncryptMessage(EncryptMessageType.AGREE);
            parseEncryptPassword(encryptBody);
        }

        EventBus.getDefault().register(handleChatEvent);


    }
 
Example #18
Source File: CommunityController.java    From nono-android with GNU General Public License v3.0 5 votes vote down vote up
public static void editPost(final String question_id,final String title,final String content ,final String tagList){
    ServiceFactory.getPostService().editPost(AuthBody.getAuthBodyMap(new Pair<>("question_id", question_id)
            , new Pair<>("question_title", title)
            , new Pair<>("question_detail", content)
            , new Pair<>("tags", tagList)
    ))
            .subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<WonderFull>() {
                @Override
                public void call(WonderFull wonderFull) {
                    WonderFull.verify(wonderFull);
                    if (wonderFull.state_code == 0) {
                        Toast.makeText(MyApp.getInstance().getApplicationContext(), "乾坤大挪移成功~", Toast.LENGTH_SHORT).show();
                        EventBus.getDefault().post(new EditCommunityItemEvent(question_id,title,content,tagList));
                    } else  if (wonderFull.state_code == -2){
                        Toast.makeText(MyApp.getInstance().getApplicationContext(), "乾坤大挪移失败,想必是服务器坏了!", Toast.LENGTH_SHORT).show();
                    }
                    else if (wonderFull.state_code == -1){
                        Toast.makeText(MyApp.getInstance().getApplicationContext(), "权限不足!", Toast.LENGTH_SHORT).show();
                    }
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    Toast.makeText(MyApp.getInstance().getApplicationContext(), "服务器生病了,请稍后再试~", Toast.LENGTH_SHORT).show();
                }
            });
}
 
Example #19
Source File: ActionTeslaFragment.java    From rnd-android-wear-tesla with MIT License 5 votes vote down vote up
private void setSetPassengerTempViews() {
    ClimateStateLoadedEvent event = EventBus.getDefault().getStickyEvent(ClimateStateLoadedEvent.class);
    if (event != null) {
        mActionButtonText.setText(String.valueOf(event.getClimateState().getPassengerTempSetting()) + "°C");
    }
    mActionLabel1.setText(getString(R.string.set_passenger_temp));
}
 
Example #20
Source File: RobotInfoActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
@Override
public void setUnfollowRobotResult(boolean b) {
    if (b) {
        EventBus.getDefault().post(new EventBusEvent.CancelFollowRobot(robotId));
        this.finish();
    }
}
 
Example #21
Source File: QChatLoginPresenter.java    From imsdk-android with MIT License 5 votes vote down vote up
public void loginByToken(final String plat) {
    LoginAPI.getQchatToken(PhoneInfoUtils.getUniqueID(), com.qunar.im.protobuf.common.CurrentPreference.getInstance().getQvt(),plat, new ProtocolCallback.UnitCallback<GeneralJson>() {
        @Override
        public void onCompleted(GeneralJson generalJson) {
            if (generalJson.ret && generalJson.data != null) {
                String username = generalJson.data.get("username");
                String token = generalJson.data.get("token");
                if (!TextUtils.isEmpty(username) && !TextUtils.isEmpty(token)) {
                    CurrentPreference.getInstance().setUserid(username);
                    String password = "{\"token\":{\"plat\":\""+plat+"\", \"macCode\":\""
                            + PhoneInfoUtils.getUniqueID() + "\", \"token\":\""
                            + token + "\"}}";
                    getStandardUserDefaults().newEditor(CommonConfig.globalContext).putObject(Constants.Preferences.lastuserid, username).synchronize();
                    getStandardUserDefaults().newEditor(CommonConfig.globalContext).putObject(Constants.Preferences.usertoken, password).synchronize();
                    if (!EventBus.getDefault().isRegistered(QChatLoginPresenter.this)) {
                        EventBus.getDefault().register(QChatLoginPresenter.this);
                    }
                    autoLogin();
                } else {
                    if(loginView != null)
                        loginView.setLoginResult(false, 100);
                }
            } else {
                if(loginView != null)
                    loginView.setLoginResult(false, 100);
            }
        }

        @Override
        public void onFailure(String errMsg) {
            if(loginView != null)
                loginView.setLoginResult(false, 100);
        }
    });
}
 
Example #22
Source File: BaseActivity.java    From DesignOverlay-Android with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (shouldRegisterToEventBus()) {
        EventBus.getDefault().register(this);
    }
}
 
Example #23
Source File: CareAddEditBehaviorFragment.java    From arcusandroid with Apache License 2.0 5 votes vote down vote up
@Override public void onResume() {
    super.onResume();

    if (TextUtils.isEmpty(modelIDToEdit)) {
        return;
    }

    Activity activity = getActivity();
    String title = getTitle();
    if (!TextUtils.isEmpty(title) && activity != null) {
        activity.setTitle(title);
    }

    showProgressBar();
    listener = CareBehaviorController.instance().setCallback(this);
    saveListener = CareBehaviorController.instance().setSaveCallback(this);
    if (isEditMode) {
        CareBehaviorController.instance().editExistingBehaviorByID(modelIDToEdit);
    }
    else {
        CareBehaviorController.instance().addBehaviorByTemplateID(modelIDToEdit);
    }

    if (!EventBus.getDefault().isRegistered(this)) {
        EventBus.getDefault().register(this);
    }
}
 
Example #24
Source File: MainActivity.java    From amiibo with GNU General Public License v2.0 5 votes vote down vote up
@DebugLog
@Override
protected void onResume() {
    super.onResume();
    EventBus.getDefault().register(this);

    ((ApplicationController) getApplication()).tryUpdateFromNetwork(this);

    checkIntentForPushFragment();
}
 
Example #25
Source File: bQ.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public void onCheckedChanged(CompoundButton compoundbutton, boolean flag)
{
    if (flag)
    {
        SettingFragment.a(a).enableInComingCallTime();
    } else
    {
        SettingFragment.a(a).disableInComingCallTime();
    }
    SettingFragment.a(a).setNeedSyncServer(2);
    Keeper.keepPersonInfo(SettingFragment.a(a));
    EventBus.getDefault().post(new EventSettingFragmentUpdate());
}
 
Example #26
Source File: ChatActivity.java    From PlayTogether with Apache License 2.0 5 votes vote down vote up
@Override
	public void afterCreate()
	{
		mConversationId = getIntent().getStringExtra(EXTRA_CONVERSATION_ID);
		String conversationName = getIntent().getStringExtra(EXTRA_CONVERSATION_NAME);
		if (mConversationId == null)
		{
			Toast.makeText(this, "无效会话", Toast.LENGTH_SHORT).show();
			finish();
		}
		//用于查看当前会话是否可见,如果可见,不更新首页的未读数量
		NotificationUtils.addTag(mConversationId);
		ActionBar actionBar = getSupportActionBar();
		if (actionBar != null) actionBar.setTitle("");
		if (conversationName == null)
			mTvTitle.setText("陌生人");
		else mTvTitle.setText(conversationName);
		EventBus.getDefault().register(this);
		mHandler = new ChatHandler();
		//隐藏图片展示框,这里不需要,因为在 gallery 一点击确定直接发送出去即可
		mRlSelectPic.setVisibility(View.GONE);
		//获取消息列表并显示加载中
		mController.getNewlyMessageData(mConversationId);
		showProgress();
		initEvent();
		//初始化recyclerview
		mDatas = new ArrayList<>();
//		mAdapter = new ChatAdapter(this, mDatas, mChatUserBll);
//		mRvChatMessage.setAdapter(mAdapter);
		mRvChatMessage.setLayoutManager(mLayoutManager = new LinearLayoutManager(this,
						LinearLayoutManager
										.VERTICAL, false));
		mRvChatMessage.setItemAnimator(new SlideInUpAnimator(new OvershootInterpolator(1.0f)));
	}
 
Example #27
Source File: ImageClipActivity.java    From imsdk-android with MIT License 5 votes vote down vote up
void initViews() {
    QtNewActionBar qtNewActionBar = (QtNewActionBar)findViewById(R.id.my_action_bar);
    setNewActionBar(qtNewActionBar);
    setActionBarRightText(R.string.atom_ui_common_use);
    setActionBarRightTextClick(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent resultData = new Intent();
            if (enableClip) {
                Bitmap clipBitmap = getBitmap();
                File tempFile = new File(FileUtils.getExternalFilesDir(ImageClipActivity.this),
                        "temp_gravatar.jpeg");
                ImageUtils.saveBitmap(clipBitmap, tempFile);
                EventBus.getDefault().post(new EventBusEvent.GravanterSelected(tempFile));
                IMNotificaitonCenter.getInstance().postMainThreadNotificationName(QtalkEvent.GravanterSelected,tempFile);
            } else {
                if (!chk_use_origin.isChecked()) {
                    File target = new File(cameraPath.substring(0, cameraPath.lastIndexOf("."))
                            + "_cmp.jpeg");
                    target = ImageUtils.compressFile(selectedImg, target);
                    if (target.exists()) {
                        cameraPath = target.getAbsolutePath();
                    }
                }
                resultData.putExtra(KEY_CAMERA_PATH, cameraPath);
                setResult(RESULT_OK, resultData);
            }
            finish();
        }
    });
    if (!inited) {
        source_pic.setOnTouchListener(this);
        if (selectedImg != null) {
            initClipView();
        } else {
            startCamera();
        }
        inited = true;
    }
}
 
Example #28
Source File: VideoDownloadHelper.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
private void showDownloadSizeExceedDialog(final ArrayList<DownloadEntry> de,
                                          final int noOfDownloads, final FragmentActivity activity, final DownloadManagerCallback callback) {
    Map<String, String> dialogMap = new HashMap<String, String>();
    dialogMap.put("title", activity.getString(R.string.download_exceed_title));
    dialogMap.put("message_1", activity.getString(R.string.download_exceed_message));
    downloadFragment = DownloadSizeExceedDialog.newInstance(dialogMap,
            new IDialogCallback() {
                @Override
                public void onPositiveClicked() {
                    if (!de.isEmpty()) {
                        startDownload(de, activity, callback);

                        final DownloadEntry downloadEntry = de.get(0);
                        analyticsRegistry.trackSubSectionBulkVideoDownload(downloadEntry.getSectionName(),
                                downloadEntry.getChapterName(), downloadEntry.getEnrollmentId(),
                                noOfDownloads);
                        EventBus.getDefault().post(new BulkVideosDownloadStartedEvent());
                    }
                }

                @Override
                public void onNegativeClicked() {
                    //  updateList();
                    downloadFragment.dismiss();
                    EventBus.getDefault().post(new BulkVideosDownloadCancelledEvent());
                }
            });
    downloadFragment.setStyle(DialogFragment.STYLE_NO_TITLE, 0);
    downloadFragment.show(activity.getSupportFragmentManager(), "dialog");
    downloadFragment.setCancelable(false);
}
 
Example #29
Source File: ImagesPagerFragment.java    From MultiImagePicker with MIT License 5 votes vote down vote up
private void updateDisplayedImage(final int index) {
    EventBus.getDefault().post(new Events.OnChangingDisplayedImageEvent(mSelectedAlbum.imageList.get(index)));
    //Because index starts from 0
    final int realPosition = index + 1;
    final String actionbarTitle = getResources().getString(R.string.image_position_in_view_pager).replace("%", realPosition + "").replace("$", mSelectedAlbum.imageList.size() + "");
    ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(actionbarTitle);

}
 
Example #30
Source File: StatusRecyclerAdapter.java    From Rumble with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onClick(View v)
{
    PopupMenu popupMenu =  new PopupMenu(activity, v);
    popupMenu.getMenu().add(Menu.NONE, 1, Menu.NONE, R.string.status_more_option_like);
    popupMenu.getMenu().add(Menu.NONE, 2, Menu.NONE, R.string.status_more_option_save);
    popupMenu.getMenu().add(Menu.NONE, 3, Menu.NONE, R.string.status_more_option_delete);
    popupMenu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            int pos = getAdapterPosition();
            switch (menuItem.getItemId()) {
                case 1:
                    EventBus.getDefault().post(new UserLikedStatus(statuses.get(pos)));
                    return true;
                case 2:
                    EventBus.getDefault().post(new UserSavedStatus(statuses.get(pos)));
                    return true;
                case 3:
                    EventBus.getDefault().post(new UserDeleteStatus(statuses.get(pos)));
                    return true;
                default:
                    return false;
            }
        }
    });
    popupMenu.show();
}