mirror of
https://github.com/ZCShou/GoGoGo.git
synced 2026-06-13 21:00:55 +08:00
更新了代码风格
This commit is contained in:
parent
9b414a0856
commit
5a36983573
Binary file not shown.
@ -45,7 +45,7 @@
|
||||
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
|
||||
|
||||
<application
|
||||
android:name=".LocationApplication"
|
||||
android:name=".GoApplication"
|
||||
android:allowBackup="false"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
|
||||
@ -1,25 +1,21 @@
|
||||
package com.zcshou.gogogo;
|
||||
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.text.InputType;
|
||||
import android.text.TextUtils;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.preference.EditTextPreference;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.Preference.OnPreferenceChangeListener;
|
||||
|
||||
import com.zcshou.utils.AppUtils;
|
||||
import com.zcshou.utils.DeviceIdUtils;
|
||||
|
||||
/* */
|
||||
public class FragmentSettings extends PreferenceFragmentCompat implements OnPreferenceChangeListener {
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.O)
|
||||
@Override
|
||||
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
|
||||
// Load the preferences from an XML resource
|
||||
|
||||
@ -12,7 +12,7 @@ import com.google.android.gms.ads.initialization.OnInitializationCompleteListene
|
||||
|
||||
|
||||
@SuppressLint("Registered")
|
||||
public class LocationApplication extends Application {
|
||||
public class GoApplication extends Application {
|
||||
public Vibrator mVibrator;
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -49,15 +49,13 @@ public class HistoryActivity extends BaseActivity {
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.history_list);
|
||||
Log.d("HistoryActivity", "SQLiteDatabase init");
|
||||
|
||||
ActionBar actionBar = getSupportActionBar();
|
||||
if(actionBar != null){
|
||||
if(actionBar != null) {
|
||||
actionBar.setHomeButtonEnabled(true);
|
||||
actionBar.setDisplayHomeAsUpEnabled(true);
|
||||
}
|
||||
|
||||
//sqlite
|
||||
try {
|
||||
HistoryLocationDataBaseHelper hisLocDBHelper = new HistoryLocationDataBaseHelper(getApplicationContext());
|
||||
sqLiteDatabase = hisLocDBHelper.getWritableDatabase();
|
||||
@ -87,6 +85,55 @@ public class HistoryActivity extends BaseActivity {
|
||||
setSearchViewListener();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
sqLiteDatabase.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this add items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_history, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == android.R.id.home) {
|
||||
this.finish(); // back button
|
||||
return true;
|
||||
} else if (id == R.id.action_delete) {
|
||||
new AlertDialog.Builder(HistoryActivity.this)
|
||||
.setTitle("Warning")//这里是表头的内容
|
||||
.setMessage("确定要删除全部历史记录吗?")//这里是中间显示的具体信息
|
||||
.setPositiveButton("确定",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
boolean deleteRet = deleteRecord(sqLiteDatabase, -1);
|
||||
|
||||
if (deleteRet) {
|
||||
DisplayToast("删除成功!");
|
||||
initListView();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
private void initListView() {
|
||||
allHistoryRecord = fetchAllRecord(sqLiteDatabase);
|
||||
|
||||
@ -331,55 +378,6 @@ public class HistoryActivity extends BaseActivity {
|
||||
return deleteRet;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
sqLiteDatabase.close();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this add items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_history, menu);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == android.R.id.home) {
|
||||
this.finish(); // back button
|
||||
return true;
|
||||
} else if (id == R.id.action_delete) {
|
||||
new AlertDialog.Builder(HistoryActivity.this)
|
||||
.setTitle("Warning")//这里是表头的内容
|
||||
.setMessage("确定要删除全部历史记录吗?")//这里是中间显示的具体信息
|
||||
.setPositiveButton("确定",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
boolean deleteRet = deleteRecord(sqLiteDatabase, -1);
|
||||
|
||||
if (deleteRet) {
|
||||
DisplayToast("删除成功!");
|
||||
initListView();
|
||||
}
|
||||
}
|
||||
})
|
||||
.setNegativeButton("取消",
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
public void DisplayToast(String str) {
|
||||
Toast toast = Toast.makeText(this, str, Toast.LENGTH_LONG);
|
||||
toast.setGravity(Gravity.TOP, 0, 220);
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.zcshou.gogogo;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
@ -87,7 +86,7 @@ import com.google.android.gms.ads.InterstitialAd;
|
||||
import com.google.android.gms.ads.LoadAdError;
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
// import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.json.JSONArray;
|
||||
@ -195,7 +194,6 @@ public class MainActivity extends BaseActivity
|
||||
|
||||
private InterstitialAd mInterstitialAd;
|
||||
|
||||
@RequiresApi(api = Build.VERSION_CODES.M)
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -321,6 +319,271 @@ public class MainActivity extends BaseActivity
|
||||
initGoogleAD();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.d("MainActivity", "onPause");
|
||||
log.debug("MainActivity: onPause");
|
||||
mMapView.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.d("MainActivity", "onPause");
|
||||
log.debug("MainActivity: onPause");
|
||||
mMapView.onResume();
|
||||
super.onResume();
|
||||
//为系统的方向传感器注册监听器
|
||||
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.d("MainActivity", "onStop");
|
||||
log.debug("MainActivity: onStop");
|
||||
//取消注册传感器监听
|
||||
mSensorManager.unregisterListener(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.d("MainActivity", "onDestroy");
|
||||
|
||||
if (isMockServStart) {
|
||||
Intent mockLocServiceIntent = new Intent(MainActivity.this, GoService.class);
|
||||
stopService(mockLocServiceIntent);
|
||||
}
|
||||
|
||||
// 退出时销毁定位
|
||||
if (isMapLoc) {
|
||||
mLocClient.stop();
|
||||
}
|
||||
|
||||
// 关闭定位图层
|
||||
mBaiduMap.setMyLocationEnabled(false);
|
||||
mMapView.onDestroy();
|
||||
|
||||
mMapView = null;
|
||||
|
||||
//poi search destroy
|
||||
mSuggestionSearch.destroy();
|
||||
|
||||
//close db
|
||||
locHistoryDB.close();
|
||||
searchHistoryDB.close();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// DrawerLayout drawer = findViewById(id.drawer_layout);
|
||||
//
|
||||
// if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
// drawer.closeDrawer(GravityCompat.START);
|
||||
// } else {
|
||||
// super.onBackPressed();
|
||||
// }
|
||||
moveTaskToBack(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
//找到searchView
|
||||
searchItem = menu.findItem(id.action_search);
|
||||
searchView = (SearchView) searchItem.getActionView();
|
||||
//searchView.setIconified(false);// 设置searchView处于展开状态
|
||||
searchView.onActionViewExpanded();// 当展开无输入内容的时候,没有关闭的图标
|
||||
// searchView.setIconifiedByDefault(true);//默认为true在框内,设置false则在框外
|
||||
//searchView.setSubmitButtonEnabled(false);//显示提交按钮
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
// Do something when collapsed
|
||||
menu.setGroupVisible(0, true);
|
||||
menu.setGroupVisible(1, true);
|
||||
// searchView.setIconified(false);// 设置searchView处于展开状态
|
||||
// mSearchList.setVisibility(View.GONE);
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
mHistorylinearLayout.setVisibility(View.INVISIBLE);
|
||||
return true; // Return true to collapse action view
|
||||
}
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
// Do something when expanded
|
||||
menu.setGroupVisible(0, false);
|
||||
menu.setGroupVisible(1, false);
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
//展示搜索历史
|
||||
List<Map<String, Object>> data = getSearchHistory();
|
||||
|
||||
if (data.size() > 0) {
|
||||
simAdapt = new SimpleAdapter(
|
||||
MainActivity.this,
|
||||
data,
|
||||
layout.search_record_item,
|
||||
new String[] {"search_key", "search_description", "search_timestamp", "search_isLoc", "search_longitude", "search_latitude"}, // 与下面数组元素要一一对应
|
||||
new int[] {id.search_key, id.search_description, id.search_timestamp, id.search_isLoc, id.search_longitude, id.search_latitude});
|
||||
mSearchHistoryList.setAdapter(simAdapt);
|
||||
mHistorylinearLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
return true; // Return true to expand action view
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
try {
|
||||
isSubmit = true;
|
||||
mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
|
||||
.keyword(query)
|
||||
.city(mCurrentCity)
|
||||
);
|
||||
//搜索历史 插表参数
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("SearchKey", query);
|
||||
contentValues.put("Description", "搜索...");
|
||||
contentValues.put("IsLocate", 0);
|
||||
contentValues.put("TimeStamp", System.currentTimeMillis() / 1000);
|
||||
|
||||
if (!saveSelectSearchItem(searchHistoryDB, contentValues)) {
|
||||
Log.e("DATABASE", "saveSelectSearchItem[SearchHistory] error");
|
||||
log.error("DATABASE: saveSelectSearchItem[SearchHistory] error");
|
||||
} else {
|
||||
Log.d("DATABASE", "saveSelectSearchItem[SearchHistory] success");
|
||||
log.debug("DATABASE: saveSelectSearchItem[SearchHistory] success");
|
||||
}
|
||||
|
||||
mBaiduMap.clear();
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
} catch (Exception e) {
|
||||
DisplayToast("搜索失败,请检查网络连接");
|
||||
Log.d("HTTP", "搜索失败,请检查网络连接");
|
||||
log.debug("HTTP: 搜索失败,请检查网络连接");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
//当输入框内容改变的时候回调
|
||||
//搜索历史置为不可见
|
||||
mHistorylinearLayout.setVisibility(View.INVISIBLE);
|
||||
|
||||
if (!newText.equals("")) {
|
||||
//do search
|
||||
//WATCH ME
|
||||
try {
|
||||
mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
|
||||
.keyword(newText)
|
||||
.city(mCurrentCity)
|
||||
);
|
||||
// poiSearch.searchInCity((new PoiCitySearchOption())
|
||||
// .city(mCurrentCity)
|
||||
// .keyword(newText)
|
||||
// .pageCapacity(30)
|
||||
// .pageNum(0));
|
||||
} catch (Exception e) {
|
||||
DisplayToast("搜索失败,请检查网络连接");
|
||||
Log.d("HTTP", "搜索失败,请检查网络连接");
|
||||
log.debug("HTTP: 搜索失败,请检查网络连接");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.main_menu_action_setting) {
|
||||
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.main_menu_action_latlng) {
|
||||
showInputLatLngDialog();
|
||||
} else if (id == R.id.action_faq) {
|
||||
showFaqDialog();
|
||||
} else if (id == R.id.main_menu_action_history) {
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_history) {
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.nav_settings) {
|
||||
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.nav_contact) {
|
||||
Intent i = new Intent(Intent.ACTION_SEND);
|
||||
// i.setType("text/plain"); //模拟器请使用这行
|
||||
i.setType("message/rfc822"); // 真机上使用这行
|
||||
i.putExtra(Intent.EXTRA_EMAIL,
|
||||
new String[] {"zcsexp@gmail.com"});
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "SUGGESTION");
|
||||
startActivity(Intent.createChooser(i,
|
||||
"Select email application."));
|
||||
} else if (id == R.id.nav_dev) {
|
||||
try {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
DisplayToast("无法跳转到开发者选项,请先确保您的设备已处于开发者模式");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent sensorEvent) {
|
||||
double x = sensorEvent.values[0];
|
||||
|
||||
if (Math.abs(x - lastX) > 1.0) {
|
||||
mCurrentDirection = (int) x;
|
||||
locData = new MyLocationData.Builder()
|
||||
.accuracy(mCurrentAccracy)
|
||||
// 此处设置开发者获取到的方向信息,顺时针0-360
|
||||
.direction(mCurrentDirection).latitude(mCurrentLat)
|
||||
.longitude(mCurrentLon).build();
|
||||
mBaiduMap.setMyLocationData(locData);
|
||||
}
|
||||
|
||||
lastX = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int i) {
|
||||
}
|
||||
|
||||
private void initGoogleAD() {
|
||||
// 横幅广告
|
||||
AdView mAdView = findViewById(R.id.ad_view);
|
||||
@ -431,7 +694,6 @@ public class MainActivity extends BaseActivity
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void setUserLimitInfo() {
|
||||
// 从上到下逐级获取
|
||||
View navHeaderView = mNavigationView.getHeaderView(0);
|
||||
@ -1657,271 +1919,6 @@ public class MainActivity extends BaseActivity
|
||||
mSuggestionSearch.setOnGetSuggestionResultListener(listener);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent sensorEvent) {
|
||||
double x = sensorEvent.values[0];
|
||||
|
||||
if (Math.abs(x - lastX) > 1.0) {
|
||||
mCurrentDirection = (int) x;
|
||||
locData = new MyLocationData.Builder()
|
||||
.accuracy(mCurrentAccracy)
|
||||
// 此处设置开发者获取到的方向信息,顺时针0-360
|
||||
.direction(mCurrentDirection).latitude(mCurrentLat)
|
||||
.longitude(mCurrentLon).build();
|
||||
mBaiduMap.setMyLocationData(locData);
|
||||
}
|
||||
|
||||
lastX = x;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAccuracyChanged(Sensor sensor, int i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.d("MainActivity", "onPause");
|
||||
log.debug("MainActivity: onPause");
|
||||
mMapView.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.d("MainActivity", "onPause");
|
||||
log.debug("MainActivity: onPause");
|
||||
mMapView.onResume();
|
||||
super.onResume();
|
||||
//为系统的方向传感器注册监听器
|
||||
mSensorManager.registerListener(this, mSensor, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.d("MainActivity", "onStop");
|
||||
log.debug("MainActivity: onStop");
|
||||
//取消注册传感器监听
|
||||
mSensorManager.unregisterListener(this);
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.d("MainActivity", "onDestroy");
|
||||
|
||||
if (isMockServStart) {
|
||||
Intent mockLocServiceIntent = new Intent(MainActivity.this, GoService.class);
|
||||
stopService(mockLocServiceIntent);
|
||||
}
|
||||
|
||||
// 退出时销毁定位
|
||||
if (isMapLoc) {
|
||||
mLocClient.stop();
|
||||
}
|
||||
|
||||
// 关闭定位图层
|
||||
mBaiduMap.setMyLocationEnabled(false);
|
||||
mMapView.onDestroy();
|
||||
|
||||
mMapView = null;
|
||||
|
||||
//poi search destroy
|
||||
mSuggestionSearch.destroy();
|
||||
|
||||
//close db
|
||||
locHistoryDB.close();
|
||||
searchHistoryDB.close();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
// DrawerLayout drawer = findViewById(id.drawer_layout);
|
||||
//
|
||||
// if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
// drawer.closeDrawer(GravityCompat.START);
|
||||
// } else {
|
||||
// super.onBackPressed();
|
||||
// }
|
||||
moveTaskToBack(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(final Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.menu_main, menu);
|
||||
//找到searchView
|
||||
searchItem = menu.findItem(id.action_search);
|
||||
searchView = (SearchView) searchItem.getActionView();
|
||||
//searchView.setIconified(false);// 设置searchView处于展开状态
|
||||
searchView.onActionViewExpanded();// 当展开无输入内容的时候,没有关闭的图标
|
||||
// searchView.setIconifiedByDefault(true);//默认为true在框内,设置false则在框外
|
||||
//searchView.setSubmitButtonEnabled(false);//显示提交按钮
|
||||
searchItem.setOnActionExpandListener(new MenuItem.OnActionExpandListener() {
|
||||
@Override
|
||||
public boolean onMenuItemActionCollapse(MenuItem item) {
|
||||
// Do something when collapsed
|
||||
menu.setGroupVisible(0, true);
|
||||
menu.setGroupVisible(1, true);
|
||||
// searchView.setIconified(false);// 设置searchView处于展开状态
|
||||
// mSearchList.setVisibility(View.GONE);
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
mHistorylinearLayout.setVisibility(View.INVISIBLE);
|
||||
return true; // Return true to collapse action view
|
||||
}
|
||||
@Override
|
||||
public boolean onMenuItemActionExpand(MenuItem item) {
|
||||
// Do something when expanded
|
||||
menu.setGroupVisible(0, false);
|
||||
menu.setGroupVisible(1, false);
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
//展示搜索历史
|
||||
List<Map<String, Object>> data = getSearchHistory();
|
||||
|
||||
if (data.size() > 0) {
|
||||
simAdapt = new SimpleAdapter(
|
||||
MainActivity.this,
|
||||
data,
|
||||
layout.search_record_item,
|
||||
new String[] {"search_key", "search_description", "search_timestamp", "search_isLoc", "search_longitude", "search_latitude"}, // 与下面数组元素要一一对应
|
||||
new int[] {id.search_key, id.search_description, id.search_timestamp, id.search_isLoc, id.search_longitude, id.search_latitude});
|
||||
mSearchHistoryList.setAdapter(simAdapt);
|
||||
mHistorylinearLayout.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
return true; // Return true to expand action view
|
||||
}
|
||||
});
|
||||
|
||||
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
|
||||
@Override
|
||||
public boolean onQueryTextSubmit(String query) {
|
||||
try {
|
||||
isSubmit = true;
|
||||
mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
|
||||
.keyword(query)
|
||||
.city(mCurrentCity)
|
||||
);
|
||||
//搜索历史 插表参数
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put("SearchKey", query);
|
||||
contentValues.put("Description", "搜索...");
|
||||
contentValues.put("IsLocate", 0);
|
||||
contentValues.put("TimeStamp", System.currentTimeMillis() / 1000);
|
||||
|
||||
if (!saveSelectSearchItem(searchHistoryDB, contentValues)) {
|
||||
Log.e("DATABASE", "saveSelectSearchItem[SearchHistory] error");
|
||||
log.error("DATABASE: saveSelectSearchItem[SearchHistory] error");
|
||||
} else {
|
||||
Log.d("DATABASE", "saveSelectSearchItem[SearchHistory] success");
|
||||
log.debug("DATABASE: saveSelectSearchItem[SearchHistory] success");
|
||||
}
|
||||
|
||||
mBaiduMap.clear();
|
||||
mSearchlinearLayout.setVisibility(View.INVISIBLE);
|
||||
} catch (Exception e) {
|
||||
DisplayToast("搜索失败,请检查网络连接");
|
||||
Log.d("HTTP", "搜索失败,请检查网络连接");
|
||||
log.debug("HTTP: 搜索失败,请检查网络连接");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onQueryTextChange(String newText) {
|
||||
//当输入框内容改变的时候回调
|
||||
//搜索历史置为不可见
|
||||
mHistorylinearLayout.setVisibility(View.INVISIBLE);
|
||||
|
||||
if (!newText.equals("")) {
|
||||
//do search
|
||||
//WATCH ME
|
||||
try {
|
||||
mSuggestionSearch.requestSuggestion((new SuggestionSearchOption())
|
||||
.keyword(newText)
|
||||
.city(mCurrentCity)
|
||||
);
|
||||
// poiSearch.searchInCity((new PoiCitySearchOption())
|
||||
// .city(mCurrentCity)
|
||||
// .keyword(newText)
|
||||
// .pageCapacity(30)
|
||||
// .pageNum(0));
|
||||
} catch (Exception e) {
|
||||
DisplayToast("搜索失败,请检查网络连接");
|
||||
Log.d("HTTP", "搜索失败,请检查网络连接");
|
||||
log.debug("HTTP: 搜索失败,请检查网络连接");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
// Handle action bar item clicks here. The action bar will
|
||||
// automatically handle clicks on the Home/Up button, so long
|
||||
// as you specify a parent activity in AndroidManifest.xml.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.main_menu_action_setting) {
|
||||
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.main_menu_action_latlng) {
|
||||
showInputLatLngDialog();
|
||||
} else if (id == R.id.action_faq) {
|
||||
showFaqDialog();
|
||||
} else if (id == R.id.main_menu_action_history) {
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_history) {
|
||||
Intent intent = new Intent(MainActivity.this, HistoryActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.nav_settings) {
|
||||
Intent intent = new Intent(MainActivity.this, SettingsActivity.class);
|
||||
startActivity(intent);
|
||||
} else if (id == R.id.nav_contact) {
|
||||
Intent i = new Intent(Intent.ACTION_SEND);
|
||||
// i.setType("text/plain"); //模拟器请使用这行
|
||||
i.setType("message/rfc822"); // 真机上使用这行
|
||||
i.putExtra(Intent.EXTRA_EMAIL,
|
||||
new String[] {"zcsexp@gmail.com"});
|
||||
i.putExtra(Intent.EXTRA_SUBJECT, "SUGGESTION");
|
||||
startActivity(Intent.createChooser(i,
|
||||
"Select email application."));
|
||||
} else if (id == R.id.nav_dev) {
|
||||
try {
|
||||
Intent intent = new Intent(Settings.ACTION_APPLICATION_DEVELOPMENT_SETTINGS);
|
||||
startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
DisplayToast("无法跳转到开发者选项,请先确保您的设备已处于开发者模式");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//定位SDK监听函数
|
||||
public class LocationGoListener extends BDAbstractLocationListener {
|
||||
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
package com.zcshou.gogogo;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@ -19,7 +18,6 @@ import androidx.preference.PreferenceManager;
|
||||
import android.os.SystemClock;
|
||||
import android.text.SpannableStringBuilder;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.Window;
|
||||
@ -98,6 +96,119 @@ public class WelcomeActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
time.cancel();
|
||||
threadExecutor.shutdownNow();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == SDK_PERMISSION_REQUEST) {
|
||||
int i;
|
||||
for (i = 0; i < ReqPermissions.size(); i++) {
|
||||
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
|
||||
break;// Permission Denied 权限被拒绝
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ReqPermissions.size()) {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
} else {
|
||||
isPermission = false;
|
||||
startBtn.setText("权限不足");
|
||||
startBtn.setClickable(true);
|
||||
}
|
||||
}
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
class TimeCount extends CountDownTimer {
|
||||
public TimeCount(long millisInFuture, long countDownInterval) {
|
||||
super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {//计时完毕时触发
|
||||
startMainActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) { //计时过程显示
|
||||
startBtn.setText(String.format(Locale.getDefault(), "%d秒", millisUntilFinished / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
private void requestNeedPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
||||
// 定位精确位置
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
||||
}
|
||||
|
||||
//悬浮窗
|
||||
// if (checkSelfPermission(Manifest.permission.SYSTEM_ALERT_WINDOW) != PackageManager.PERMISSION_GRANTED) {
|
||||
// permissions.add(Manifest.permission.SYSTEM_ALERT_WINDOW);
|
||||
// }
|
||||
|
||||
/*
|
||||
* 读写权限和电话状态权限非必要权限(建议授予)只会申请一次,用户同意或者禁止,只会弹一次
|
||||
*/
|
||||
// 读写权限
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
// 读取电话状态权限
|
||||
if (checkSelfPermission( Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.READ_PHONE_STATE);
|
||||
}
|
||||
|
||||
if (ReqPermissions.size() > 0) {
|
||||
requestPermissions(ReqPermissions.toArray(new String[0]), SDK_PERMISSION_REQUEST);
|
||||
} else {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//WIFI是否可用
|
||||
private boolean isWifiConnected() {
|
||||
ConnectivityManager mConnectivityManager = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
@ -240,125 +351,6 @@ public class WelcomeActivity extends BaseActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
Log.d("WelcomeActivity", "onPause");
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
Log.d("WelcomeActivity", "onPause");
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
Log.d("WelcomeActivity", "onStop");
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Log.d("WelcomeActivity", "onDestroy");
|
||||
time.cancel();
|
||||
threadExecutor.shutdownNow();
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
private void requestNeedPermissions() {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
|
||||
// 定位精确位置
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.ACCESS_FINE_LOCATION);
|
||||
}
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.ACCESS_COARSE_LOCATION);
|
||||
}
|
||||
|
||||
//悬浮窗
|
||||
// if (checkSelfPermission(Manifest.permission.SYSTEM_ALERT_WINDOW) != PackageManager.PERMISSION_GRANTED) {
|
||||
// permissions.add(Manifest.permission.SYSTEM_ALERT_WINDOW);
|
||||
// }
|
||||
|
||||
/*
|
||||
* 读写权限和电话状态权限非必要权限(建议授予)只会申请一次,用户同意或者禁止,只会弹一次
|
||||
*/
|
||||
// 读写权限
|
||||
if (checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.READ_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
if (checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.WRITE_EXTERNAL_STORAGE);
|
||||
}
|
||||
|
||||
// 读取电话状态权限
|
||||
if (checkSelfPermission( Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
|
||||
ReqPermissions.add(Manifest.permission.READ_PHONE_STATE);
|
||||
}
|
||||
|
||||
if (ReqPermissions.size() > 0) {
|
||||
requestPermissions(ReqPermissions.toArray(new String[0]), SDK_PERMISSION_REQUEST);
|
||||
} else {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@TargetApi(23)
|
||||
@Override
|
||||
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
|
||||
if (requestCode == SDK_PERMISSION_REQUEST) {
|
||||
int i;
|
||||
for (i = 0; i < ReqPermissions.size(); i++) {
|
||||
if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
|
||||
break;// Permission Denied 权限被拒绝
|
||||
}
|
||||
}
|
||||
|
||||
if (i >= ReqPermissions.size()) {
|
||||
isPermission = true;
|
||||
if (!isLimit) {
|
||||
time.start();
|
||||
}
|
||||
} else {
|
||||
isPermission = false;
|
||||
startBtn.setText("权限不足");
|
||||
startBtn.setClickable(true);
|
||||
}
|
||||
}
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||
}
|
||||
|
||||
class TimeCount extends CountDownTimer {
|
||||
public TimeCount(long millisInFuture, long countDownInterval) {
|
||||
super(millisInFuture, countDownInterval);//参数依次为总时长,和计时的时间间隔
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {//计时完毕时触发
|
||||
startMainActivity();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTick(long millisUntilFinished) { //计时过程显示
|
||||
startBtn.setText(String.format(Locale.getDefault(), "%d秒", millisUntilFinished / 1000));
|
||||
}
|
||||
}
|
||||
|
||||
private class TimeTask implements Runnable {
|
||||
private final String[] ntpServerPool = {"ntp1.aliyun.com", "ntp2.aliyun.com", "ntp3.aliyun.com", "ntp4.aliyun.com", "ntp5.aliyun.com", "ntp6.aliyun.com", "ntp7.aliyun.com",
|
||||
"cn.pool.ntp.org", "cn.ntp.org.cn", "sg.pool.ntp.org", "tw.pool.ntp.org", "jp.pool.ntp.org", "hk.pool.ntp.org", "th.pool.ntp.org",
|
||||
@ -383,7 +375,6 @@ public class WelcomeActivity extends BaseActivity {
|
||||
time.start();
|
||||
}
|
||||
} else {
|
||||
isLimit = true;
|
||||
startBtn.setClickable(true);
|
||||
startBtn.setText("无法连接服务器");
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.zcshou.joystick;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
@ -32,7 +31,6 @@ public class ButtonView extends LinearLayout {
|
||||
boolean isWestSouth;
|
||||
ImageButton btnWestSouth;
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
public ButtonView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||
super(context, attrs, defStyleAttr);
|
||||
LayoutInflater.from(context).inflate(R.layout.joystick_button, this);
|
||||
@ -55,7 +53,6 @@ public class ButtonView extends LinearLayout {
|
||||
initButtonView();
|
||||
}
|
||||
|
||||
@SuppressLint("InflateParams")
|
||||
private void initButtonView() {
|
||||
isCenter = false;
|
||||
btnCenter = findViewById(R.id.btn_center);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user