/** Called when the activity is first created */ @Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "LoaderActivity created"); super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.content); // Instantiate custom adapter mAdapter = new LoaderAdapter(); // Handle listview and assign adapter mListView = (ListView) findViewById(R.id.content_list_view); mListView.setAdapter(mAdapter); mListView.setVisibility(View.GONE); mListView.setOnItemLongClickListener( new AdapterView.OnItemLongClickListener() { public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { selectItem(position); return true; } }); mStatusLabel = (TextView) findViewById(R.id.content_status_label); mStatusLabel.setVisibility(View.VISIBLE); String userHash = NavigineApp.Settings.getString("user_hash", ""); if (userHash.length() == 0) showUserHashDialog(); else refreshMapList(); }
@Override public boolean onCreateOptionsMenu(Menu menu) { Log.d(TAG, "onCreateOptionsMenu"); getMenuInflater().inflate(R.menu.main, menu); this.menu = menu; return true; }
@Override public void onPause() { Log.d(TAG, "LoaderActivity paused"); super.onPause(); mTimerTask.cancel(); mTimerTask = null; }
@Override public boolean onCreateOptionsMenu(Menu menu) { Log.d(TAG, "Create menu options"); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.loader_menu, menu); menu.findItem(R.id.loader_menu_refresh_map_list).setVisible(mLoader < 0); return true; }
private void updateLoader() { if (NavigineApp.Navigation == null) return; // Log.d(TAG, String.format(Locale.ENGLISH, "Update loader: %d", mLoader)); long timeNow = DateTimeUtils.currentTimeMillis(); if (mLoader < 0) return; int status = LocationLoader.checkLocationLoader(mLoader); if (status < 100) { if ((Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT / 3 && status == 0) || (Math.abs(timeNow - mLoaderTime) > LOADER_TIMEOUT)) { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("Loading timeout!\nPlease, check your internet connection!"); Log.d(TAG, String.format(Locale.ENGLISH, "Load stopped on timeout!")); LocationLoader.stopLocationLoader(mLoader); mLoader = -1; } else { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText(String.format(Locale.ENGLISH, "Loading content (%d%%)", status)); } } else { Log.d(TAG, String.format(Locale.ENGLISH, "Load finished with result: %d", status)); LocationLoader.stopLocationLoader(mLoader); mLoader = -1; if (status == 100) { parseMapsXml(); if (mInfoList.isEmpty()) { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("No locations available"); } else { mListView.setVisibility(View.VISIBLE); mStatusLabel.setVisibility(View.GONE); } } else { mListView.setVisibility(View.GONE); mStatusLabel.setVisibility(View.VISIBLE); mStatusLabel.setText("Error loading!\nPlease, check your ID!"); } } }
@Override public void onItemClick(AdapterView adapterView, View view, int position, long id) { Log.d(TAG, "onItemClick: position: " + position + ", id: " + id); String item = listAdapter.getItem(position).trim(); if (item.endsWith(" =")) { item = item.substring(0, item.length() - 2); } if (!item.startsWith("no result")) { inputView.append(item); } }
private void refreshMapList() { if (mLoader >= 0) return; String userHash = NavigineApp.Settings.getString("user_hash", ""); if (userHash.length() == 0) return; // Starting new loader String fileName = LocationLoader.getLocationDir(NavigineApp.AppContext, null) + "/maps.xml"; new File(fileName).delete(); mLoader = LocationLoader.startLocationLoader(null, fileName, true); mLoaderTime = DateTimeUtils.currentTimeMillis(); mInfoList = new ArrayList<LocationInfo>(); Log.d(TAG, String.format(Locale.ENGLISH, "Location loader started: %d", mLoader)); }
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.d(TAG, "onOptionsItemSelected: itemId: " + item.getItemId()); switch (item.getItemId()) { case R.id.menu_clear: Log.d(TAG, "onOptionsItemSelected: menu_clear"); clear(); break; case R.id.menu_help: Log.d(TAG, "onOptionsItemSelected: menu_help"); startActivity(new Intent(Intent.ACTION_VIEW, null, this, Help.class)); break; case R.id.menu_about: Log.d(TAG, "onOptionsItemSelected: menu_about"); Messages.about(this); break; } return super.onOptionsItemSelected(item); }
@Override public boolean onEditorAction(TextView textView, int actionId, KeyEvent keyEvent) { Log.d(TAG, "onEditorAction: actionId: " + actionId + ", keyEvent: " + keyEvent); if ((actionId == EditorInfo.IME_ACTION_DONE) || ((keyEvent != null) && (keyEvent.getKeyCode() == KeyEvent.KEYCODE_ENTER))) { Log.d(TAG, "onEditorAction: IME_ACTION_DONE || KEYCODE_ENTER"); String input = textView.getText().toString().trim(); if (input.length() > 0) { String result = ""; try { result += calculator.calculate(input); } catch (Exception e) { result = "no result (" + e.getMessage() + ")"; } if (listAdapter.getCount() > 0) { listAdapter.add(""); } listAdapter.add(input + " ="); if (input.indexOf("@") > -1) { listAdapter.add(calculator.getEquation() + " ="); } listAdapter.add(result); listAdapter.notifyDataSetChanged(); inputView.endBatchEdit(); inputView.setText(""); hideKeyboard(); } } return false; }
@Override public void onResume() { Log.d(TAG, "LoaderActivity resumed"); super.onResume(); // Starting interface updates mTimerTask = new TimerTask() { @Override public void run() { mHandler.post(mRunnable); } }; mTimer.schedule(mTimerTask, 100, 100); }
@Override public void onCreate(Bundle savedInstanceState) { Log.d(TAG, "onCreate"); super.onCreate(savedInstanceState); Thread.currentThread().setUncaughtExceptionHandler(this); setContentView(R.layout.main); inputView = (EditText) findViewById(R.id.input_view); inputView.setOnEditorActionListener(this); listAdapter = new ArrayAdapter<String>(this, R.layout.row); listAdapter.setNotifyOnChange(true); resultsView = (ListView) this.findViewById(R.id.results_view); resultsView.setAdapter(listAdapter); resultsView.setOnItemClickListener(this); }
private void updateLocationLoaders() { if (NavigineApp.Navigation == null) return; long timeNow = DateTimeUtils.currentTimeMillis(); mUpdateLocationLoadersTime = timeNow; synchronized (mLoaderMap) { Iterator<Map.Entry<String, LoaderState>> iter = mLoaderMap.entrySet().iterator(); while (iter.hasNext()) { Map.Entry<String, LoaderState> entry = iter.next(); LoaderState loader = entry.getValue(); if (loader.state < 100) { loader.timeLabel = timeNow; if (loader.type == DOWNLOAD) loader.state = LocationLoader.checkLocationLoader(loader.id); if (loader.type == UPLOAD) loader.state = LocationLoader.checkLocationUploader(loader.id); } else if (loader.state == 100) { String archivePath = NavigineApp.Navigation.getArchivePath(); String locationFile = LocationLoader.getLocationFile(NavigineApp.AppContext, loader.location); if (archivePath != null && archivePath.equals(locationFile)) { Log.d(TAG, "Reloading archive " + archivePath); if (NavigineApp.Navigation.loadArchive(archivePath)) { SharedPreferences.Editor editor = NavigineApp.Settings.edit(); editor.putString("map_file", archivePath); editor.commit(); } } if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id); if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id); iter.remove(); } else { // Load failed if (Math.abs(timeNow - loader.timeLabel) > 5000) { if (loader.type == DOWNLOAD) LocationLoader.stopLocationLoader(loader.id); if (loader.type == UPLOAD) LocationLoader.stopLocationUploader(loader.id); iter.remove(); } } } } updateLocalVersions(); mAdapter.updateList(); }
private void startUpload(int index) { if (NavigineApp.Navigation == null) return; String userHash = NavigineApp.Settings.getString("user_hash", ""); if (userHash.length() == 0) return; LocationInfo info = mInfoList.get(index); String location = new String(info.title); Log.d(TAG, String.format(Locale.ENGLISH, "Start upload: %s", location)); synchronized (mLoaderMap) { if (!mLoaderMap.containsKey(location)) { LoaderState loader = new LoaderState(); loader.location = location; loader.type = UPLOAD; loader.id = LocationLoader.startLocationUploader(location, info.archiveFile, true); mLoaderMap.put(location, loader); } } mAdapter.updateList(); }
public void tryLogin() { mName = mEtAccount.getText().toString(); mPassword = mEtPassword.getText().toString(); if (mName.equals("") || mPassword.length() < 5) { // Please Specify Your Name and Sex" Toast.makeText( MainActivity.this, "Please Specify Your Name and Password correctly", Toast.LENGTH_LONG) .show(); } else { mUserInfo = new UserInfo(mName, 0, 0, 0, 0, 0, 0); /* if mNetcon is connected already, close it first */ /* here we use try because mNetCon might not have been instantiated yet */ /* try { NetConnect.getnetConnect().closeNetConnect(); } catch (Exception e) {} try { InitData.closeInitData(); FriendListInfo.closeFriendListInfo(); ChatServiceData.closeChatServiceData(); } catch (Exception e) {} */ CloseAll.closeAll(); /* to establish a new connect */ NetworkService.getInstance().onInit(this); NetworkService.getInstance().setupConnection(); if (NetworkService.getInstance().getIsConnected()) { String usrInfo = mUserInfo.toString() + GlobalStrings.signinDivider + mPassword + GlobalStrings.signinDivider; NetworkService.getInstance().sendUpload(GlobalMsgTypes.msgHandShake, usrInfo); } else { NetworkService.getInstance().closeConnection(); Toast.makeText(this, "failed to connect to Server", Toast.LENGTH_LONG).show(); return; } InitData initData = InitData.getInitData(); initData.start(); try { initData.join(); } catch (Exception e) { } mUserInfo = initData.getUserInfo(); Log.d( "connectedApp isonline : ", "" + mUserInfo.getIsOnline() + "+++++++++++++" + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); if (mUserInfo.getId() < 0) { Toast.makeText(this, "invalid username or password", Toast.LENGTH_SHORT).show(); return; } Log.d( "connectedApp isonline : ", "" + mUserInfo.getIsOnline() + "+++++++++++++" + "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"); ConnectedApp connected_app0 = ConnectedApp.getInstance(); // connected_app0.setConnect(mNetCon); connected_app0.setUserInfo(mUserInfo); connected_app0.clearListActivity(); connected_app0.instantiateListActivity(); Intent intent0 = new Intent(MainActivity.this, MainBodyActivity.class); // intent0.putExtra("username", mUserInfo.getName()); // intent0.putExtra("usersex", mUserInfo.getSex()); startActivity(intent0); finish(); } }
public void nextLevel() { boolean loaded = false; final GameBoard boardView = (GameBoard) this.findViewById(R.id.gameBoard); this.level++; AssetManager am = getResources().getAssets(); try { List<String> allTutoLevels = new LinkedList<String>(Arrays.asList(am.list("levels/tutorial"))); // if(addMsg){ // allTutoLevels.addAll(Arrays.asList(am.list("msg"))); // } Log.d(TAG, allTutoLevels.toString()); for (String name : allTutoLevels) { if (name.startsWith(this.level + ".")) { BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/tutorial/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); loaded = true; } } } catch (IOException e) { e.printStackTrace(); } if (!loaded) { Random r = new Random(); List<String> allLevels = new ArrayList<>(); try { allLevels = Arrays.asList(am.list("levels")); } catch (IOException e) { } if (r.nextBoolean() && !allLevels.isEmpty() && allLevels.size() != allDoneLevels.size()) { try { int nLevel; do { nLevel = r.nextInt(allLevels.size()); } while (allDoneLevels.contains(allLevels.get(nLevel))); String name = allLevels.get(nLevel); BufferedReader br = new BufferedReader(new InputStreamReader(am.open("levels/" + name))); String line; String levelJSON = ""; while ((line = br.readLine()) != null) { levelJSON += line + "\n"; } br.close(); allDoneLevels.add(name); game.initGame( levelJSON, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } catch (IOException e) { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } else { this.game.initGame( level, boardView.getMeasuredWidth() / 60, boardView.getMeasuredHeight() / 60); } } // am.close(); boardView.setGame(this.game); boardView.invalidate(); boardView.getHowdyShadeView().invalidate(); Toast.makeText(this, this.level + "", Toast.LENGTH_SHORT).show(); Log.i( TAG, "Max tiles : " + (boardView.getMeasuredWidth() / 60) * (boardView.getMeasuredHeight() / 60)); }
public void setLog(String text) { if (isLog()) Log.d(text); }
@Override public boolean onPrepareOptionsMenu(Menu menu) { Log.d(TAG, "Prepare menu options"); menu.findItem(R.id.loader_menu_refresh_map_list).setVisible(mLoader < 0); return true; }
@Override public void onDestroy() { Log.d(TAG, "LoaderActivity destroyed"); super.onDestroy(); }