@Test public void setShouldReplaceDuplicates() { alarmManager.set( AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); alarmManager.set( AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); assertEquals(1, shadowAlarmManager.getScheduledAlarms().size()); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_nutrients_new_item); setTag(this.getClass().getSimpleName()); // set activity name toolbarsManager = new ToolbarsManager(this); toolbarsManager.setNameActivity(this.getTitle().toString()); nutrientsDBAdapter = new NutrientsDBAdapter(); newName = (EditText) findViewById(R.id.nutrients_new_name); newProteins = (EditText) findViewById(R.id.nutrients_new_proteins); newFats = (EditText) findViewById(R.id.nutrients_new_fats); newCarbs = (EditText) findViewById(R.id.nutrients_new_carbs); newCalories = (EditText) findViewById(R.id.nutrients_new_calories); warningToast = Toast.makeText(this, "", Toast.LENGTH_SHORT); toastText = (TextView) warningToast.getView().findViewById(android.R.id.message); toastText.setTextColor(Color.RED); intent = getIntent(); if (intent.getAction().equals(Intent.ACTION_EDIT)) atEdit = true; // It's updating existing item, not inserting else atEdit = false; // It's inserting new row }
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); int group = ExpandableListView.getPackedPositionGroup(info.packedPosition); int child = ExpandableListView.getPackedPositionChild(info.packedPosition); Cursor parentCursor = ((MyExpandableListAdapter) expandableListView.getExpandableListAdapter()).getCursor(); parentCursor.moveToPosition(group); selectedParentRowId = parentCursor.getString(parentCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_ROWID)); selectedParentName = parentCursor.getString(parentCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_NAME)); // Create a context menu for child items if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { Cursor childCursor = ((MyExpandableListAdapter) expandableListView.getExpandableListAdapter()) .getChildrenCursor(parentCursor); childCursor.moveToPosition(child); selectedChildRowId = parentCursor.getString(childCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_ROWID)); selectedChildName = childCursor.getString(childCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_NAME)); selectedChildGlass = childCursor.getString(childCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_GLASS)); selectedChildSpoon = childCursor.getString(childCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_SPOON)); selectedChildPcs = childCursor.getString(childCursor.getColumnIndexOrThrow(FoodsWeightDBAdapter.KEY_PCS)); menu.setHeaderTitle( "<<" + selectedParentName + ">>" + Character.toString((char) 10) + selectedChildName); for (int i = 0; i < menuItems.length; i++) { menu.add(Menu.NONE, i, i, menuItems[i]); } } if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { selectedChildRowId = "-1"; Log.i(getTag(), "group = " + group + " child = " + child); menu.setHeaderTitle(selectedParentName); for (int i = 0; i < menuItems.length; i++) { menu.add(Menu.NONE, i, i, menuItems[i]); } } }
@Override public boolean onTouchEvent(MotionEvent event) { pointx = (float) event.getX(); pointy = (float) event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: // 按下 if (backgroundSound.isPointInRect(pointx, pointy)) { // 跳转到游戏界面 backgroundSound.setswitch(); activity.soundFlag = backgroundSound.isOnflag(); // 设置声音的开启,关闭 } else if (soundEffect.isPointInRect(pointx, pointy)) { soundEffect.setswitch(); activity.soundPoolFlag = soundEffect.isOnflag(); } break; case MotionEvent.ACTION_UP: // 抬起 break; } return true; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); // 去掉标题栏 setContentView(R.layout.friend_list); application = (MyApplication) this.getApplicationContext(); initData(); // 初始化数据 initImageView(); // 初始化动画 initUI(); // 初始化界面 }
private Webcamera saveWebcameraAndCreateNewIfNecessary( Webcamera webcamera, String name, ArrayList<Webcamera> results) { if (name.equalsIgnoreCase(myActivity.getString(R.string.webkamera))) { if (webcamera != null) { webcamera.setLatLng(); results.add(webcamera); } webcamera = new Webcamera(); } return webcamera; }
@Test public void shouldSupportSet() throws Exception { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); alarmManager.set( AlarmManager.ELAPSED_REALTIME, 0, PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0)); ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm(); assertThat(scheduledAlarm).isNotNull(); }
@Test public void shouldSupportGetNextScheduledAlarm() throws Exception { assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); long now = new Date().getTime(); PendingIntent pendingIntent = PendingIntent.getActivity(activity, 0, new Intent(activity, activity.getClass()), 0); alarmManager.set(AlarmManager.ELAPSED_REALTIME, now, pendingIntent); ShadowAlarmManager.ScheduledAlarm scheduledAlarm = shadowAlarmManager.getNextScheduledAlarm(); assertThat(shadowAlarmManager.getNextScheduledAlarm()).isNull(); assertScheduledAlarm(now, pendingIntent, scheduledAlarm); }
@Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); super.setContentView(R.layout.tea_video_grid); context = TeaVideoActivity.this; myHandle = new MyHandle(); SqliteHelper sqliteHelper = new SqliteHelper(context); DatabaseManager.initializeInstance(sqliteHelper); teaVideoGV = (GridView) super.findViewById(R.id.tea_video_gv); /*new Thread(new Runnable() { @Override public void run() {*/ myHandle.sendEmptyMessage(1); /* } }).start();*/ teaVideoGV.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub // TODO Auto-generated method stub Intent intent = new Intent(); intent.putExtra( "url", serverUrl + dataList.get(dataList.size() - position - 1).getVideourl()); intent.setClass(TeaVideoActivity.this, VideoPlayer.class); startActivity(intent); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_foods_weight); setTag(this.getClass().getSimpleName()); foodsWeightDBAdapter = new FoodsWeightDBAdapter(); menuItems = getResources().getStringArray(R.array.tables_context_menu); toolbarsManager = new ToolbarsManager(this); toolbarsManager.setNameActivity(this.getTitle().toString()); // Set invisible and layout space free toolbarsManager.setFunctionalToolbarVisible(View.GONE); }
public ArrayList<Webcamera> readFeed(XmlPullParser parser) throws IOException, XmlPullParserException { ArrayList<Webcamera> results = new ArrayList<>(); Webcamera webcamera = null; parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.webkameraer)); while (parser.next() != XmlPullParser.END_DOCUMENT) { String name = parser.getName(); if (name != null) { webcamera = saveWebcameraAndCreateNewIfNecessary(webcamera, name, results); readAndHandleNextXmlTag(webcamera, parser, name); } } return results; }
@Override protected void onResume() { // 如果从后台恢复,服务被系统干掉,就重启一下服务 // TODO Auto-generated method stub newNum = application.getRecentNum(); // 从新获取一下全局变量 if (!application.isClientStart()) { Intent service = new Intent(this, GetMsgService.class); startService(service); } new SharePreferenceUtil(this, Constants.SAVE_USER).setIsStart(false); NotificationManager manager = application.getmNotificationManager(); if (manager != null) { manager.cancel(Constants.NOTIFY_ID); application.setNewMsgNum(0); // 把消息数目置0 application.getmRecentAdapter().notifyDataSetChanged(); } super.onResume(); }
private void readAndHandleNextXmlTag(Webcamera webcamera, XmlPullParser parser, String name) throws IOException, XmlPullParserException { if (webcamera != null) { switch (name) { case ("url"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.url)); webcamera.setUrl(readText(parser)); break; case ("stedsnavn"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.stedsnavn)); webcamera.setStedsnavn(readText(parser)); break; case ("veg"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.veg)); webcamera.setVeg(readText(parser)); break; case ("landsdel"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.landsdel)); webcamera.setLandsdel(readText(parser)); break; case ("lengdegrad"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.lengdegrad)); webcamera.setLengdegrad(readText(parser)); break; case ("breddegrad"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.breddegrad)); webcamera.setBreddegrad(readText(parser)); break; case ("info"): parser.require(XmlPullParser.START_TAG, ns, myActivity.getString(R.string.info)); webcamera.setInfo(readText(parser)); break; default: break; } } }
@Override public void onResume() { super.onResume(); if (atEdit) fillData(); }
@Override protected void onDestroy() { // TODO Auto-generated method stub super.onDestroy(); if (messageDB != null) messageDB.close(); }
protected void onPostExecute(ArrayList<Webcamera> webcameras) { myActivity.webcamerasMyActivity.clear(); myActivity.webcamerasMyActivity.addAll(webcameras); myActivity.setCoords(); }
@Override public void onResume() { super.onResume(); displayListView(); }
public void onDestroy() { super.onDestroy(); db.close(); }
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.tick_project); setTitle(R.string.editAscent); setupActionBar(); Bundle b = this.getIntent().getExtras(); long projectId = b.getLong("projectId"); db = new InternalDB(this); project = db.getProject(projectId); TextView routeView = (TextView) this.findViewById(R.id.route); routeView.setText( project.getRoute().getName() + " " + project.getRoute().getGrade() + " (" + project.getRoute().getCrag().getName() + ")"); TextView dateDisplay = (TextView) findViewById(R.id.dateDisplay); Date date = new Date(); String dateString = fmt.format(date); dateDisplay.setText(dateString); cal.setTime(date); Button dateButton = (Button) findViewById(R.id.pickDate); dateButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { showDialog(DATE_DIALOG_ID); } }); EditText commentsView = (EditText) findViewById(R.id.comment); EditText attemptsView = (EditText) findViewById(R.id.attempts); attemptsView.setText("" + project.getAttempts()); RatingBar starsView = (RatingBar) findViewById(R.id.stars); Button cancel = (Button) findViewById(R.id.cancel); cancel.setOnClickListener( new OnClickListener() { public void onClick(View v) { setResult(RESULT_CANCELED); finish(); } }); Button button = (Button) findViewById(R.id.ok); button.setOnClickListener( new OnClickListener() { public void onClick(View v) { String text = null; EditText attemptsView = (EditText) findViewById(R.id.attempts); String string = attemptsView.getText().toString(); int attempts = 1; if (string != null) { try { attempts = Integer.parseInt(string); } catch (NumberFormatException e) { } } TextView dateDisplay = (TextView) findViewById(R.id.dateDisplay); String dateString = dateDisplay.getText().toString(); Date date = new Date(); try { date = fmt.parse(dateString); } catch (ParseException e) { } RatingBar starsView = (RatingBar) findViewById(R.id.stars); EditText commentView = (EditText) findViewById(R.id.comment); String comment = commentView.getText().toString(); db.addAscent(project, date, attempts, 3, comment, (int) starsView.getRating()); text = "Ascent added"; if (text != null) { Toast.makeText(TickProjectActivity.this, text, Toast.LENGTH_SHORT).show(); } setResult(RESULT_OK); finish(); } }); }