use of android.view.GestureDetector in project Anki-Android by Ramblurr.
the class DeckPicker method onCreate.
// ----------------------------------------------------------------------------
// ANDROID METHODS
// ----------------------------------------------------------------------------
/** Called when the activity is first created. */
@Override
protected void onCreate(Bundle savedInstanceState) throws SQLException {
Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate");
Intent intent = getIntent();
if (!isTaskRoot()) {
Log.i(AnkiDroidApp.TAG, "DeckPicker - onCreate: Detected multiple instance of this activity, closing it and return to root activity");
Intent reloadIntent = new Intent(DeckPicker.this, DeckPicker.class);
reloadIntent.setAction(Intent.ACTION_MAIN);
if (intent != null && intent.getExtras() != null) {
reloadIntent.putExtras(intent.getExtras());
}
if (intent != null && intent.getData() != null) {
reloadIntent.setData(intent.getData());
}
reloadIntent.addCategory(Intent.CATEGORY_LAUNCHER);
reloadIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
finish();
startActivityIfNeeded(reloadIntent, 0);
}
if (intent.getData() != null) {
mImportPath = getIntent().getData().getEncodedPath();
}
// need to start this here in order to avoid showing deckpicker before splashscreen
if (AnkiDroidApp.colIsOpen()) {
setTitle(getResources().getString(R.string.app_name));
} else {
setTitle("");
mOpenCollectionHandler.onPreExecute();
}
Themes.applyTheme(this);
super.onCreate(savedInstanceState);
// mStartedByBigWidget = intent.getIntExtra(EXTRA_START, EXTRA_START_NOTHING);
SharedPreferences preferences = restorePreferences();
// activate broadcast messages if first start of a day
if (mLastTimeOpened < UIUtils.getDayStart()) {
preferences.edit().putBoolean("showBroadcastMessageToday", true).commit();
}
preferences.edit().putLong("lastTimeOpened", System.currentTimeMillis()).commit();
// if (intent != null && intent.hasExtra(EXTRA_DECK_ID)) {
// openStudyOptions(intent.getLongExtra(EXTRA_DECK_ID, 1));
// }
BroadcastMessages.checkForNewMessages(this);
View mainView = getLayoutInflater().inflate(R.layout.deck_picker, null);
setContentView(mainView);
// check, if tablet layout
View studyoptionsFrame = findViewById(R.id.studyoptions_fragment);
mFragmented = studyoptionsFrame != null && studyoptionsFrame.getVisibility() == View.VISIBLE;
Themes.setContentStyle(mFragmented ? mainView : mainView.findViewById(R.id.deckpicker_view), Themes.CALLER_DECKPICKER);
registerExternalStorageListener();
if (!mFragmented) {
mAddButton = (ImageButton) findViewById(R.id.deckpicker_add);
mAddButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
addNote();
}
});
mCardsButton = (ImageButton) findViewById(R.id.deckpicker_card_browser);
mCardsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
openCardBrowser();
}
});
mStatsButton = (ImageButton) findViewById(R.id.statistics_all_button);
mStatsButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
showDialog(DIALOG_SELECT_STATISTICS_TYPE);
}
});
mSyncButton = (ImageButton) findViewById(R.id.sync_all_button);
mSyncButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
sync();
}
});
}
mInvalidateMenu = false;
mDeckList = new ArrayList<HashMap<String, String>>();
mDeckListView = (ListView) findViewById(R.id.files);
mDeckListAdapter = new SimpleAdapter(this, mDeckList, R.layout.deck_item, new String[] { "name", "new", "lrn", // "complMat", "complAll",
"rev", "sep", "dyn" }, new int[] { R.id.DeckPickerName, R.id.deckpicker_new, R.id.deckpicker_lrn, // R.id.deckpicker_bar_mat, R.id.deckpicker_bar_all,
R.id.deckpicker_rev, R.id.deckpicker_deck, R.id.DeckPickerName });
mDeckListAdapter.setViewBinder(new SimpleAdapter.ViewBinder() {
@Override
public boolean setViewValue(View view, Object data, String text) {
if (view.getId() == R.id.deckpicker_deck) {
if (text.equals("top")) {
view.setBackgroundResource(R.drawable.white_deckpicker_top);
return true;
} else if (text.equals("bot")) {
view.setBackgroundResource(R.drawable.white_deckpicker_bottom);
return true;
} else if (text.equals("ful")) {
view.setBackgroundResource(R.drawable.white_deckpicker_full);
return true;
} else if (text.equals("cen")) {
view.setBackgroundResource(R.drawable.white_deckpicker_center);
return true;
}
} else if (view.getId() == R.id.DeckPickerName) {
if (text.equals("d0")) {
((TextView) view).setTextColor(getResources().getColor(R.color.non_dyn_deck));
return true;
} else if (text.equals("d1")) {
((TextView) view).setTextColor(getResources().getColor(R.color.dyn_deck));
return true;
}
}
// return false;
return false;
}
});
mDeckListView.setOnItemClickListener(mDeckSelHandler);
mDeckListView.setAdapter(mDeckListAdapter);
if (mFragmented) {
mDeckListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
}
registerForContextMenu(mDeckListView);
showStartupScreensAndDialogs(preferences, 0);
if (mSwipeEnabled) {
gestureDetector = new GestureDetector(new MyGestureDetector());
mDeckListView.setOnTouchListener(new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
}
}
use of android.view.GestureDetector in project Anki-Android by Ramblurr.
the class Reviewer method initLayout.
// Set the content view to the one provided and initialize accessors.
private void initLayout(Integer layout) {
setContentView(layout);
mMainLayout = findViewById(R.id.main_layout);
Themes.setContentStyle(mMainLayout, Themes.CALLER_REVIEWER);
mCardContainer = (FrameLayout) findViewById(R.id.flashcard_frame);
setInAnimation(false);
findViewById(R.id.top_bar).setOnClickListener(mCardStatisticsListener);
mCardFrame = (FrameLayout) findViewById(R.id.flashcard);
mTouchLayer = (FrameLayout) findViewById(R.id.touch_layer);
mTouchLayer.setOnTouchListener(mGestureListener);
if (mPrefTextSelection && mLongClickWorkaround) {
mTouchLayer.setOnLongClickListener(mLongClickListener);
}
if (mPrefTextSelection) {
mClipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);
}
mCardFrame.removeAllViews();
if (!mChangeBorderStyle) {
((View) findViewById(R.id.flashcard_border)).setVisibility(View.VISIBLE);
}
// hunt for input issue 720, like android issue 3341
if (AnkiDroidApp.SDK_VERSION <= 7 && (mCard != null)) {
mCard.setFocusableInTouchMode(true);
}
// Initialize swipe
gestureDetector = new GestureDetector(new MyGestureDetector());
mProgressBar = (ProgressBar) findViewById(R.id.flashcard_progressbar);
// initialise shake detection
if (mShakeEnabled) {
mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mSensorManager.registerListener(mSensorListener, mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER), SensorManager.SENSOR_DELAY_NORMAL);
mAccel = 0.00f;
mAccelCurrent = SensorManager.GRAVITY_EARTH;
mAccelLast = SensorManager.GRAVITY_EARTH;
}
Resources res = getResources();
mEase1 = (Button) findViewById(R.id.ease1);
mEase1.setTextColor(res.getColor(R.color.next_time_failed_color));
mEase1Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease1);
mEase1Layout.setOnClickListener(mSelectEaseHandler);
mEase2 = (Button) findViewById(R.id.ease2);
mEase2.setTextColor(res.getColor(R.color.next_time_usual_color));
mEase2Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease2);
mEase2Layout.setOnClickListener(mSelectEaseHandler);
mEase3 = (Button) findViewById(R.id.ease3);
mEase3Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease3);
mEase3Layout.setOnClickListener(mSelectEaseHandler);
mEase4 = (Button) findViewById(R.id.ease4);
mEase4Layout = (LinearLayout) findViewById(R.id.flashcard_layout_ease4);
mEase4Layout.setOnClickListener(mSelectEaseHandler);
mNext1 = (TextView) findViewById(R.id.nextTime1);
mNext2 = (TextView) findViewById(R.id.nextTime2);
mNext3 = (TextView) findViewById(R.id.nextTime3);
mNext4 = (TextView) findViewById(R.id.nextTime4);
mNext1.setTextColor(res.getColor(R.color.next_time_failed_color));
mNext2.setTextColor(res.getColor(R.color.next_time_usual_color));
if (!mShowNextReviewTime) {
((TextView) findViewById(R.id.nextTimeflip)).setVisibility(View.GONE);
mNext1.setVisibility(View.GONE);
mNext2.setVisibility(View.GONE);
mNext3.setVisibility(View.GONE);
mNext4.setVisibility(View.GONE);
}
mFlipCard = (Button) findViewById(R.id.flip_card);
mFlipCardLayout = (LinearLayout) findViewById(R.id.flashcard_layout_flip);
mFlipCardLayout.setOnClickListener(mFlipCardListener);
mTextBarRed = (TextView) findViewById(R.id.red_number);
mTextBarBlack = (TextView) findViewById(R.id.black_number);
mTextBarBlue = (TextView) findViewById(R.id.blue_number);
if (!mShowRemainingCardCount) {
mTextBarRed.setVisibility(View.GONE);
mTextBarBlack.setVisibility(View.GONE);
mTextBarBlue.setVisibility(View.GONE);
}
if (mShowProgressBars) {
mSessionProgressTotalBar = (View) findViewById(R.id.daily_bar);
mSessionProgressBar = (View) findViewById(R.id.session_progress);
mProgressBars = (LinearLayout) findViewById(R.id.progress_bars);
}
mCardTimer = (Chronometer) findViewById(R.id.card_time);
if (mShowProgressBars && mProgressBars.getVisibility() != View.VISIBLE) {
switchVisibility(mProgressBars, View.VISIBLE);
}
mChosenAnswer = (TextView) findViewById(R.id.choosen_answer);
if (mPrefWhiteboard) {
mWhiteboard = new Whiteboard(this, mInvertedColors, mBlackWhiteboard);
FrameLayout.LayoutParams lp2 = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
mWhiteboard.setLayoutParams(lp2);
FrameLayout fl = (FrameLayout) findViewById(R.id.whiteboard);
fl.addView(mWhiteboard);
mWhiteboard.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
if (mShowWhiteboard) {
return false;
}
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
});
}
mAnswerField = (EditText) findViewById(R.id.answer_field);
mNextTimeTextColor = getResources().getColor(R.color.next_time_usual_color);
mNextTimeTextRecomColor = getResources().getColor(R.color.next_time_recommended_color);
mForegroundColor = getResources().getColor(R.color.next_time_usual_color);
if (mInvertedColors) {
invertColors(true);
}
mLookUpIcon = findViewById(R.id.lookup_button);
mLookUpIcon.setVisibility(View.GONE);
mLookUpIcon.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
if (clipboardHasText()) {
lookUp();
}
}
});
initControls();
}
use of android.view.GestureDetector in project Anki-Android by Ramblurr.
the class StudyOptionsFragment method createView.
protected View createView(LayoutInflater inflater, Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.i(AnkiDroidApp.TAG, "StudyOptions - createView()");
restorePreferences();
mFragmented = getActivity().getClass() != StudyOptionsActivity.class;
if (!AnkiDroidApp.colIsOpen()) {
reloadCollection();
return null;
}
// Intent intent = getActivity().getIntent();
// if (intent != null && intent.hasExtra(DeckPicker.EXTRA_DECK_ID)) {
// mCol.getDecks().select(intent.getLongExtra(DeckPicker.EXTRA_DECK_ID, 1));
// }
initAllContentViews(inflater);
if (mSwipeEnabled) {
gestureDetector = new GestureDetector(new MyGestureDetector());
gestureListener = new View.OnTouchListener() {
public boolean onTouch(View v, MotionEvent event) {
if (gestureDetector.onTouchEvent(event)) {
return true;
}
return false;
}
};
}
if (getArguments().getBoolean("onlyFnsMsg")) {
prepareCongratsView();
return mCongratsView;
} else {
// clear undo if new deck is opened (do not clear if only congrats msg is shown)
AnkiDroidApp.getCol().clearUndo();
}
mCramInitialConfig = getArguments().getBundle("cramInitialConfig");
resetAndUpdateValuesFromDeck();
return mStudyOptionsView;
}
use of android.view.GestureDetector in project platform_frameworks_base by android.
the class OverlayDisplayWindow method createWindow.
private void createWindow() {
LayoutInflater inflater = LayoutInflater.from(mContext);
mWindowContent = inflater.inflate(com.android.internal.R.layout.overlay_display_window, null);
mWindowContent.setOnTouchListener(mOnTouchListener);
mTextureView = (TextureView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_texture);
mTextureView.setPivotX(0);
mTextureView.setPivotY(0);
mTextureView.getLayoutParams().width = mWidth;
mTextureView.getLayoutParams().height = mHeight;
mTextureView.setOpaque(false);
mTextureView.setSurfaceTextureListener(mSurfaceTextureListener);
mTitleTextView = (TextView) mWindowContent.findViewById(com.android.internal.R.id.overlay_display_window_title);
mTitleTextView.setText(mTitle);
mWindowParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.TYPE_DISPLAY_OVERLAY);
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED;
if (mSecure) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_SECURE;
}
if (DISABLE_MOVE_AND_RESIZE) {
mWindowParams.flags |= WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
}
mWindowParams.privateFlags |= WindowManager.LayoutParams.PRIVATE_FLAG_FORCE_HARDWARE_ACCELERATED;
mWindowParams.alpha = WINDOW_ALPHA;
mWindowParams.gravity = Gravity.TOP | Gravity.LEFT;
mWindowParams.setTitle(mTitle);
mGestureDetector = new GestureDetector(mContext, mOnGestureListener);
mScaleGestureDetector = new ScaleGestureDetector(mContext, mOnScaleGestureListener);
// Set the initial position and scale.
// The position and scale will be clamped when the display is first shown.
mWindowX = (mGravity & Gravity.LEFT) == Gravity.LEFT ? 0 : mDefaultDisplayInfo.logicalWidth;
mWindowY = (mGravity & Gravity.TOP) == Gravity.TOP ? 0 : mDefaultDisplayInfo.logicalHeight;
mWindowScale = INITIAL_SCALE;
}
use of android.view.GestureDetector in project platform_frameworks_base by android.
the class DividerView method onFinishInflate.
@Override
protected void onFinishInflate() {
super.onFinishInflate();
mHandle = (DividerHandleView) findViewById(R.id.docked_divider_handle);
mBackground = findViewById(R.id.docked_divider_background);
mMinimizedShadow = (MinimizedDockShadow) findViewById(R.id.minimized_dock_shadow);
mHandle.setOnTouchListener(this);
mDividerWindowWidth = getResources().getDimensionPixelSize(com.android.internal.R.dimen.docked_stack_divider_thickness);
mDividerInsets = getResources().getDimensionPixelSize(com.android.internal.R.dimen.docked_stack_divider_insets);
mDividerSize = mDividerWindowWidth - 2 * mDividerInsets;
mTouchElevation = getResources().getDimensionPixelSize(R.dimen.docked_stack_divider_lift_elevation);
mLongPressEntraceAnimDuration = getResources().getInteger(R.integer.long_press_dock_anim_duration);
mGrowRecents = getResources().getBoolean(R.bool.recents_grow_in_multiwindow);
mTouchSlop = ViewConfiguration.get(mContext).getScaledTouchSlop();
mFlingAnimationUtils = new FlingAnimationUtils(getContext(), 0.3f);
updateDisplayInfo();
boolean landscape = getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
mHandle.setPointerIcon(PointerIcon.getSystemIcon(getContext(), landscape ? TYPE_HORIZONTAL_DOUBLE_ARROW : TYPE_VERTICAL_DOUBLE_ARROW));
getViewTreeObserver().addOnComputeInternalInsetsListener(this);
mHandle.setAccessibilityDelegate(mHandleDelegate);
mGestureDetector = new GestureDetector(mContext, new SimpleOnGestureListener() {
@Override
public boolean onSingleTapUp(MotionEvent e) {
if (SWAPPING_ENABLED) {
updateDockSide();
SystemServicesProxy ssp = Recents.getSystemServices();
if (mDockSide != WindowManager.DOCKED_INVALID && !ssp.isRecentsActivityVisible()) {
mWindowManagerProxy.swapTasks();
return true;
}
}
return false;
}
});
}
Aggregations