mirror of
https://github.com/freeedcom/ai-codereviewer.git
synced 2025-06-30 21:04:16 +00:00
add project adins
This commit is contained in:
parent
ad06ac5505
commit
f8f85d679d
5299 changed files with 625430 additions and 0 deletions
|
@ -0,0 +1,9 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="14dp"
|
||||
android:height="14dp"
|
||||
android:viewportWidth="24.0"
|
||||
android:viewportHeight="24.0">
|
||||
<path
|
||||
android:fillColor="@color/gradient_end"
|
||||
android:pathData="M6,18c0,0.55 0.45,1 1,1h1v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L11,19h2v3.5c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5L16,19h1c0.55,0 1,-0.45 1,-1L18,8L6,8v10zM3.5,8C2.67,8 2,8.67 2,9.5v7c0,0.83 0.67,1.5 1.5,1.5S5,17.33 5,16.5v-7C5,8.67 4.33,8 3.5,8zM20.5,8c-0.83,0 -1.5,0.67 -1.5,1.5v7c0,0.83 0.67,1.5 1.5,1.5s1.5,-0.67 1.5,-1.5v-7c0,-0.83 -0.67,-1.5 -1.5,-1.5zM15.53,2.16l1.3,-1.3c0.2,-0.2 0.2,-0.51 0,-0.71 -0.2,-0.2 -0.51,-0.2 -0.71,0l-1.48,1.48C13.85,1.23 12.95,1 12,1c-0.96,0 -1.86,0.23 -2.66,0.63L7.85,0.15c-0.2,-0.2 -0.51,-0.2 -0.71,0 -0.2,0.2 -0.2,0.51 0,0.71l1.31,1.31C6.97,3.26 6,5.01 6,7h12c0,-1.99 -0.97,-3.75 -2.47,-4.84zM10,5L9,5L9,4h1v1zM15,5h-1L14,4h1v1z"/>
|
||||
</vector>
|
|
@ -0,0 +1,100 @@
|
|||
package com.adins.mss.base.timeline;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.R;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.LocaleHelper;
|
||||
import com.google.android.gms.maps.CameraUpdateFactory;
|
||||
import com.google.android.gms.maps.GoogleMap;
|
||||
import com.google.android.gms.maps.OnMapReadyCallback;
|
||||
import com.google.android.gms.maps.SupportMapFragment;
|
||||
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
|
||||
import com.google.android.gms.maps.model.CircleOptions;
|
||||
import com.google.android.gms.maps.model.LatLng;
|
||||
import com.google.android.gms.maps.model.MarkerOptions;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
public class MapsViewer extends FragmentActivity implements OnMapReadyCallback {
|
||||
SupportMapFragment mapFragment;
|
||||
private GoogleMap mGoogleMap;
|
||||
private LatLng locationPoint;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.maps_layout);
|
||||
mapFragment = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps);
|
||||
if (savedInstanceState == null) {
|
||||
mapFragment.setRetainInstance(true);
|
||||
} else {
|
||||
mapFragment.getMapAsync(this);
|
||||
}
|
||||
initialize();
|
||||
}
|
||||
@Override
|
||||
protected void attachBaseContext(Context newBase) {
|
||||
Context context = newBase;
|
||||
Locale locale;
|
||||
try{
|
||||
locale = new Locale(GlobalData.getSharedGlobalData().getLocale());
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} catch (Exception e) {
|
||||
locale = new Locale(LocaleHelper.ENGLSIH);
|
||||
context = LocaleHelper.wrap(newBase, locale);
|
||||
} finally {
|
||||
super.attachBaseContext(context);
|
||||
}
|
||||
}
|
||||
|
||||
private void initialize() {
|
||||
if (mGoogleMap == null) {
|
||||
((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.maps)).getMapAsync(this);
|
||||
if (mGoogleMap != null) {
|
||||
setupMaps();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setupMaps() {
|
||||
try {
|
||||
String lat = getIntent().getStringExtra("latitude");
|
||||
String lng = getIntent().getStringExtra("longitude");
|
||||
int accuracy = getIntent().getIntExtra("accuracy", 0);
|
||||
double mLatitude = Double.parseDouble(lat);
|
||||
double mLongitude = Double.parseDouble(lng);
|
||||
locationPoint = new LatLng(mLatitude, mLongitude);
|
||||
mGoogleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(locationPoint, 16));
|
||||
MarkerOptions markerOptions = new MarkerOptions();
|
||||
markerOptions.position(locationPoint);
|
||||
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_GREEN));
|
||||
mGoogleMap.addMarker(markerOptions);
|
||||
|
||||
if (accuracy != 0) {
|
||||
CircleOptions circleOptions = new CircleOptions()
|
||||
.center(locationPoint)
|
||||
.radius(accuracy)
|
||||
.fillColor(0x402196F3)
|
||||
.strokeColor(Color.TRANSPARENT)
|
||||
.strokeWidth(2);
|
||||
|
||||
mGoogleMap.addCircle(circleOptions);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onMapReady(GoogleMap googleMap) {
|
||||
mGoogleMap = googleMap;
|
||||
if (mGoogleMap != null) {
|
||||
setupMaps();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
package com.adins.mss.odr.update;
|
||||
|
||||
import com.adins.mss.foundation.http.KeyValue;
|
||||
import com.adins.mss.foundation.http.MssResponseType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class JsonResponseDetailCancelOrder extends MssResponseType{
|
||||
/** Property listDetailOrder */
|
||||
@SerializedName("listDetailOrder")
|
||||
List<ResponseServer> listDetailOrder;
|
||||
|
||||
/**
|
||||
* Gets the listDetailOrder
|
||||
*/
|
||||
public List<ResponseServer> getListDetailOrder() {
|
||||
return this.listDetailOrder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the listDetailOrder
|
||||
*/
|
||||
public void setListDetailOrder(List<ResponseServer> value) {
|
||||
this.listDetailOrder = value;
|
||||
}
|
||||
|
||||
public class ResponseServer extends KeyValue {
|
||||
@SerializedName("flag")
|
||||
String flag;
|
||||
public ResponseServer(String key, String value) {
|
||||
super(key, value);
|
||||
}
|
||||
List<ResponseServer> subListResponseServer;
|
||||
|
||||
public String getFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public void setFlag(String flag) {
|
||||
this.flag = flag;
|
||||
}
|
||||
|
||||
public List<ResponseServer> getSubListResponseServer() {
|
||||
return subListResponseServer;
|
||||
}
|
||||
|
||||
public void setSubListResponseServer(List<ResponseServer> subListResponseServer) {
|
||||
this.subListResponseServer = subListResponseServer;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 5.9 KiB |
Binary file not shown.
After Width: | Height: | Size: 5.4 KiB |
|
@ -0,0 +1,17 @@
|
|||
package com.adins.mss.base.dukcapil;
|
||||
|
||||
import com.adins.mss.foundation.http.MssResponseType;
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
|
||||
public class ResponseImageDkcp extends MssResponseType {
|
||||
@SerializedName("dataDkcp")
|
||||
private ImageDkcpBean dataDkcp;
|
||||
|
||||
public ImageDkcpBean getDataDkcp() {
|
||||
return dataDkcp;
|
||||
}
|
||||
|
||||
public void setDataDkcp(ImageDkcpBean dataDkcp) {
|
||||
this.dataDkcp = dataDkcp;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,127 @@
|
|||
package com.adins.mss.odr.accounts;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.NewMainActivity;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Account;
|
||||
import com.adins.mss.foundation.dialog.NiftyDialogBuilder;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.odr.R;
|
||||
import com.adins.mss.odr.accounts.api.AccountsSearchRequest;
|
||||
import com.adins.mss.odr.accounts.api.AccountsSearchResponse;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by muhammad.aap on 11/27/2018.
|
||||
*/
|
||||
|
||||
public class GetAccount extends AsyncTask<Void, Void, ArrayList<String>>{
|
||||
private FragmentActivity activity;
|
||||
private ProgressDialog progressDialog;
|
||||
private String errMessage;
|
||||
private ArrayList<String> result = new ArrayList<String>();
|
||||
|
||||
public GetAccount(FragmentActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
super.onPreExecute();
|
||||
progressDialog = ProgressDialog.show(activity, "", activity.getString(R.string.contact_server), true);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ArrayList<String> doInBackground(Void... params) {
|
||||
if (Tool.isInternetconnected(activity)) {
|
||||
AccountsSearchRequest request = new AccountsSearchRequest();
|
||||
request.setUuid_account("");
|
||||
request.setUuid_product("");
|
||||
request.setUuid_status("");
|
||||
request.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
|
||||
String json = GsonHelper.toJson(request);
|
||||
|
||||
String url = GlobalData.getSharedGlobalData().getURL_GET_ACCOUNT();
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(activity, encrypt, decrypt);
|
||||
HttpConnectionResult serverResult = null;
|
||||
try {
|
||||
serverResult = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
AccountsSearchResponse response = null;
|
||||
if (serverResult != null && serverResult.isOK()) {
|
||||
try {
|
||||
String responseBody = serverResult.getResult();
|
||||
response = GsonHelper.fromJson(responseBody, AccountsSearchResponse.class);
|
||||
} catch (Exception e) {
|
||||
if(Global.IS_DEV) {
|
||||
e.printStackTrace();
|
||||
errMessage=e.getMessage();
|
||||
}
|
||||
}
|
||||
|
||||
List<Account> listAccounts = response.getListAccount();
|
||||
if (listAccounts != null && listAccounts.size() != 0) {
|
||||
for(Account acc : listAccounts){
|
||||
result.add(acc.getUuid_account());
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.no_data_from_server);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.server_down);
|
||||
}
|
||||
} else {
|
||||
errMessage = activity.getString(R.string.no_internet_connection);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(ArrayList<String> result) {
|
||||
super.onPostExecute(result);
|
||||
|
||||
if (progressDialog != null && progressDialog.isShowing()) {
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
|
||||
if (errMessage != null) {
|
||||
if (errMessage.equals(activity.getString(R.string.no_data_from_server))) {
|
||||
NiftyDialogBuilder builder = NiftyDialogBuilder.getInstance(activity);
|
||||
builder.withTitle("INFO")
|
||||
.withMessage(errMessage)
|
||||
.show();
|
||||
} else {
|
||||
Toast.makeText(activity, errMessage, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
Fragment fragment = new FragmentAccountList();
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putStringArrayList(Global.BUND_KEY_ACCOUNT_ID, result);
|
||||
fragment.setArguments(bundle);
|
||||
FragmentTransaction transaction = NewMainActivity.fragmentManager.beginTransaction();
|
||||
transaction.setCustomAnimations(com.adins.mss.base.R.anim.activity_open_translate, com.adins.mss.base.R.anim.activity_close_scale, com.adins.mss.base.R.anim.activity_open_scale, com.adins.mss.base.R.anim.activity_close_translate);
|
||||
transaction.replace(com.adins.mss.base.R.id.content_frame, fragment);
|
||||
transaction.addToBackStack(null);
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
|
@ -0,0 +1,203 @@
|
|||
package com.adins.mss.coll.services;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
import android.util.Log;
|
||||
|
||||
import com.adins.mss.base.GlobalData;
|
||||
import com.adins.mss.base.crashlytics.FireCrash;
|
||||
import com.adins.mss.base.util.GsonHelper;
|
||||
import com.adins.mss.base.util.Utility;
|
||||
import com.adins.mss.coll.EmergencyLockActivity;
|
||||
import com.adins.mss.coll.models.EmergencyRequest;
|
||||
import com.adins.mss.constant.Global;
|
||||
import com.adins.mss.dao.Emergency;
|
||||
import com.adins.mss.dao.GeneralParameter;
|
||||
import com.adins.mss.dao.LocationInfo;
|
||||
import com.adins.mss.dao.User;
|
||||
import com.adins.mss.foundation.db.dataaccess.EmergencyDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.GeneralParameterDataAccess;
|
||||
import com.adins.mss.foundation.db.dataaccess.UserDataAccess;
|
||||
import com.adins.mss.foundation.formatter.Tool;
|
||||
import com.adins.mss.foundation.http.HttpConnectionResult;
|
||||
import com.adins.mss.foundation.http.HttpCryptedConnection;
|
||||
import com.adins.mss.foundation.http.MssResponseType;
|
||||
import com.google.firebase.perf.FirebasePerformance;
|
||||
import com.google.firebase.perf.metrics.HttpMetric;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.Date;
|
||||
|
||||
public class EmergencyService extends Service {
|
||||
EmergencyThread emergencyThread;
|
||||
public EmergencyService(){
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
emergencyThread = new EmergencyThread(getApplicationContext());
|
||||
emergencyThread.start();
|
||||
super.onCreate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
emergencyThread.requestStop();
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected class EmergencyThread extends Thread {
|
||||
private WeakReference<Context> context;
|
||||
private volatile boolean keepRunning = true;
|
||||
private volatile boolean isWait = false;
|
||||
private long interval = Global.DEFAULT_EMERGENCY_INTERVAL_SEND;
|
||||
private Date dtm_crt;
|
||||
|
||||
public EmergencyThread(Context context) {
|
||||
this.context = new WeakReference<>(context);
|
||||
try {
|
||||
GeneralParameter gp = GeneralParameterDataAccess.getOne(context,
|
||||
UserDataAccess.getOne(getApplicationContext()).getUuid_user(),
|
||||
Global.GS_INTERVAL_EMERGENCY_MC);
|
||||
if (gp != null) {
|
||||
interval = Global.SECOND * Integer.parseInt(gp.getGs_value());
|
||||
}
|
||||
dtm_crt = new Date(System.currentTimeMillis());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
dtm_crt = new Date(System.currentTimeMillis());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if(null!=GlobalData.getSharedGlobalData().getUser()){
|
||||
GlobalData.getSharedGlobalData().getUser().setIs_emergency(Global.EMERGENCY_SEND_PENDING);
|
||||
UserDataAccess.addOrReplace(getApplicationContext(),GlobalData.getSharedGlobalData().getUser());
|
||||
} else{
|
||||
User user = UserDataAccess.getOne(getApplicationContext());
|
||||
user.setIs_emergency("2");
|
||||
UserDataAccess.addOrReplace(getApplicationContext(), user);
|
||||
}
|
||||
Emergency emergency = new Emergency();
|
||||
emergency.setUser(UserDataAccess.getOne(getApplicationContext()));
|
||||
EmergencyRequest emergencyRequest = new EmergencyRequest();
|
||||
String url = GlobalData.getSharedGlobalData().getURL_EMERGENCY();
|
||||
emergencyRequest.setDtm_emergency(dtm_crt);
|
||||
emergency.setDtm_emergency(dtm_crt);
|
||||
LocationInfo loc = Global.LTM.getCurrentLocation(Global.FLAG_LOCATION_TRACKING);
|
||||
if ("null".equalsIgnoreCase(loc.getLatitude())) {
|
||||
emergency.setLatitude("");
|
||||
} else {
|
||||
emergency.setLatitude(loc.getLatitude());
|
||||
}
|
||||
if ("null".equalsIgnoreCase(loc.getLongitude())) {
|
||||
emergency.setLongitude("");
|
||||
} else {
|
||||
emergency.setLongitude(loc.getLongitude());
|
||||
}
|
||||
try {
|
||||
GeneralParameter gp = GeneralParameterDataAccess.getOne(context.get(),
|
||||
emergency.getUuid_user(),
|
||||
Global.GS_INTERVAL_EMERGENCY_MC);
|
||||
if (gp != null) {
|
||||
interval = Global.SECOND * Integer.parseInt(gp.getGs_value());
|
||||
}
|
||||
dtm_crt = new Date(System.currentTimeMillis());
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
e.printStackTrace();
|
||||
dtm_crt = new Date(System.currentTimeMillis());
|
||||
}
|
||||
while (keepRunning) {
|
||||
try {
|
||||
synchronized (this) {
|
||||
if (isWait) {
|
||||
this.wait();
|
||||
}
|
||||
}
|
||||
|
||||
if (Tool.isInternetconnected(context.get())) {
|
||||
|
||||
boolean encrypt = GlobalData.getSharedGlobalData().isEncrypt();
|
||||
boolean decrypt = GlobalData.getSharedGlobalData().isDecrypt();
|
||||
HttpCryptedConnection httpConn = new HttpCryptedConnection(context.get(), encrypt, decrypt);
|
||||
emergencyRequest.setDtm_emergency(emergency.getDtm_emergency());
|
||||
emergencyRequest.setLatitude(emergency.getLatitude());
|
||||
emergencyRequest.setLongitude(emergency.getLongitude());
|
||||
emergencyRequest.setAudit(GlobalData.getSharedGlobalData().getAuditData());
|
||||
User user = UserDataAccess.getOne(getApplicationContext());
|
||||
if(EmergencyDataAccess.getByUser(getApplicationContext(), user.getUuid_user()).size() == 0)
|
||||
EmergencyDataAccess.add(getApplicationContext(), emergency);
|
||||
else{
|
||||
emergency = EmergencyDataAccess.getByUser(getApplicationContext(),user.getUuid_user()).get(0);
|
||||
}
|
||||
|
||||
String json = GsonHelper.toJson(emergencyRequest);
|
||||
HttpConnectionResult response = null;
|
||||
|
||||
//Firebase Performance Trace HTTP Request
|
||||
HttpMetric networkMetric =
|
||||
FirebasePerformance.getInstance().newHttpMetric(url, FirebasePerformance.HttpMethod.POST);
|
||||
Utility.metricStart(networkMetric, json);
|
||||
|
||||
try {
|
||||
response = httpConn.requestToServer(url, json, Global.DEFAULTCONNECTIONTIMEOUT);
|
||||
Utility.metricStop(networkMetric, response);
|
||||
} catch (Exception e) {
|
||||
FireCrash.log(e);
|
||||
}
|
||||
if (response.isOK()) {
|
||||
MssResponseType resp = GsonHelper.fromJson(response.getResult(), MssResponseType.class);
|
||||
if (resp.getStatus().getCode() == 0) {
|
||||
GlobalData.getSharedGlobalData().getUser().setIs_emergency(Global.EMERGENCY_SEND_SUCCESS);
|
||||
UserDataAccess.addOrReplace(getApplicationContext(),GlobalData.getSharedGlobalData().getUser());
|
||||
EmergencyLockActivity.emergencyHandler.sendEmptyMessage(0);
|
||||
requestStop();
|
||||
} else {
|
||||
try {
|
||||
Log.d("emergency", interval+"");
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
FireCrash.log(ex);
|
||||
ex.printStackTrace();
|
||||
try {
|
||||
Thread.sleep(interval);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
super.run();
|
||||
}
|
||||
|
||||
public synchronized void requestWait() {
|
||||
isWait = true;
|
||||
}
|
||||
|
||||
public synchronized void stopWaiting() {
|
||||
isWait = false;
|
||||
synchronized (this) {
|
||||
this.notifyAll();
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized void requestStop() {
|
||||
keepRunning = false;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 3.3 KiB |
|
@ -0,0 +1,208 @@
|
|||
package com.github.jjobes.slidedatetimepicker;
|
||||
|
||||
/*
|
||||
* Copyright (C) 2013 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
//package com.example.android.common.view;
|
||||
|
||||
import android.R;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.TypedValue;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
class SlidingTabStrip extends LinearLayout {
|
||||
|
||||
private static final int DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS = 2;
|
||||
private static final byte DEFAULT_BOTTOM_BORDER_COLOR_ALPHA = 0x26;
|
||||
private static final int SELECTED_INDICATOR_THICKNESS_DIPS = 6;
|
||||
private static final int DEFAULT_SELECTED_INDICATOR_COLOR = 0xFF33B5E5;
|
||||
|
||||
private static final int DEFAULT_DIVIDER_THICKNESS_DIPS = 1;
|
||||
private static final byte DEFAULT_DIVIDER_COLOR_ALPHA = 0x20;
|
||||
private static final float DEFAULT_DIVIDER_HEIGHT = 0.5f;
|
||||
|
||||
private final int mBottomBorderThickness;
|
||||
private final Paint mBottomBorderPaint;
|
||||
|
||||
private final int mSelectedIndicatorThickness;
|
||||
private final Paint mSelectedIndicatorPaint;
|
||||
|
||||
private final int mDefaultBottomBorderColor;
|
||||
|
||||
private final Paint mDividerPaint;
|
||||
private final float mDividerHeight;
|
||||
private final SimpleTabColorizer mDefaultTabColorizer;
|
||||
private int mSelectedPosition;
|
||||
private float mSelectionOffset;
|
||||
private SlidingTabLayout.TabColorizer mCustomTabColorizer;
|
||||
|
||||
SlidingTabStrip(Context context) {
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
SlidingTabStrip(Context context, AttributeSet attrs) {
|
||||
super(context, attrs);
|
||||
setWillNotDraw(false);
|
||||
|
||||
final float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
TypedValue outValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(R.attr.colorForeground, outValue, true);
|
||||
final int themeForegroundColor = outValue.data;
|
||||
|
||||
mDefaultBottomBorderColor = setColorAlpha(themeForegroundColor,
|
||||
DEFAULT_BOTTOM_BORDER_COLOR_ALPHA);
|
||||
|
||||
mDefaultTabColorizer = new SimpleTabColorizer();
|
||||
mDefaultTabColorizer.setIndicatorColors(DEFAULT_SELECTED_INDICATOR_COLOR);
|
||||
mDefaultTabColorizer.setDividerColors(setColorAlpha(themeForegroundColor,
|
||||
DEFAULT_DIVIDER_COLOR_ALPHA));
|
||||
|
||||
mBottomBorderThickness = (int) (DEFAULT_BOTTOM_BORDER_THICKNESS_DIPS * density);
|
||||
mBottomBorderPaint = new Paint();
|
||||
mBottomBorderPaint.setColor(mDefaultBottomBorderColor);
|
||||
|
||||
mSelectedIndicatorThickness = (int) (SELECTED_INDICATOR_THICKNESS_DIPS * density);
|
||||
mSelectedIndicatorPaint = new Paint();
|
||||
|
||||
mDividerHeight = DEFAULT_DIVIDER_HEIGHT;
|
||||
mDividerPaint = new Paint();
|
||||
mDividerPaint.setStrokeWidth((int) (DEFAULT_DIVIDER_THICKNESS_DIPS * density));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the alpha value of the {@code color} to be the given {@code alpha} value.
|
||||
*/
|
||||
private static int setColorAlpha(int color, byte alpha) {
|
||||
return Color.argb(alpha, Color.red(color), Color.green(color), Color.blue(color));
|
||||
}
|
||||
|
||||
/**
|
||||
* Blend {@code color1} and {@code color2} using the given ratio.
|
||||
*
|
||||
* @param ratio of which to blend. 1.0 will return {@code color1}, 0.5 will give an even blend,
|
||||
* 0.0 will return {@code color2}.
|
||||
*/
|
||||
private static int blendColors(int color1, int color2, float ratio) {
|
||||
final float inverseRation = 1f - ratio;
|
||||
float r = (Color.red(color1) * ratio) + (Color.red(color2) * inverseRation);
|
||||
float g = (Color.green(color1) * ratio) + (Color.green(color2) * inverseRation);
|
||||
float b = (Color.blue(color1) * ratio) + (Color.blue(color2) * inverseRation);
|
||||
return Color.rgb((int) r, (int) g, (int) b);
|
||||
}
|
||||
|
||||
void setCustomTabColorizer(SlidingTabLayout.TabColorizer customTabColorizer) {
|
||||
mCustomTabColorizer = customTabColorizer;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void setSelectedIndicatorColors(int... colors) {
|
||||
// Make sure that the custom colorizer is removed
|
||||
mCustomTabColorizer = null;
|
||||
mDefaultTabColorizer.setIndicatorColors(colors);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void setDividerColors(int... colors) {
|
||||
// Make sure that the custom colorizer is removed
|
||||
mCustomTabColorizer = null;
|
||||
mDefaultTabColorizer.setDividerColors(colors);
|
||||
invalidate();
|
||||
}
|
||||
|
||||
void onViewPagerPageChanged(int position, float positionOffset) {
|
||||
mSelectedPosition = position;
|
||||
mSelectionOffset = positionOffset;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDraw(Canvas canvas) {
|
||||
final int height = getHeight();
|
||||
final int childCount = getChildCount();
|
||||
final int dividerHeightPx = (int) (Math.min(Math.max(0f, mDividerHeight), 1f) * height);
|
||||
final SlidingTabLayout.TabColorizer tabColorizer = mCustomTabColorizer != null
|
||||
? mCustomTabColorizer
|
||||
: mDefaultTabColorizer;
|
||||
|
||||
// Thick colored underline below the current selection
|
||||
if (childCount > 0) {
|
||||
View selectedTitle = getChildAt(mSelectedPosition);
|
||||
int left = selectedTitle.getLeft();
|
||||
int right = selectedTitle.getRight();
|
||||
int color = tabColorizer.getIndicatorColor(mSelectedPosition);
|
||||
|
||||
if (mSelectionOffset > 0f && mSelectedPosition < (getChildCount() - 1)) {
|
||||
int nextColor = tabColorizer.getIndicatorColor(mSelectedPosition + 1);
|
||||
if (color != nextColor) {
|
||||
color = blendColors(nextColor, color, mSelectionOffset);
|
||||
}
|
||||
|
||||
// Draw the selection partway between the tabs
|
||||
View nextTitle = getChildAt(mSelectedPosition + 1);
|
||||
left = (int) (mSelectionOffset * nextTitle.getLeft() +
|
||||
(1.0f - mSelectionOffset) * left);
|
||||
right = (int) (mSelectionOffset * nextTitle.getRight() +
|
||||
(1.0f - mSelectionOffset) * right);
|
||||
}
|
||||
|
||||
mSelectedIndicatorPaint.setColor(color);
|
||||
|
||||
canvas.drawRect(left, height - mSelectedIndicatorThickness, right,
|
||||
height, mSelectedIndicatorPaint);
|
||||
}
|
||||
|
||||
// Thin underline along the entire bottom edge
|
||||
canvas.drawRect(0, height - mBottomBorderThickness, getWidth(), height, mBottomBorderPaint);
|
||||
|
||||
// Vertical separators between the titles
|
||||
int separatorTop = (height - dividerHeightPx) / 2;
|
||||
for (int i = 0; i < childCount - 1; i++) {
|
||||
View child = getChildAt(i);
|
||||
mDividerPaint.setColor(tabColorizer.getDividerColor(i));
|
||||
canvas.drawLine(child.getRight(), separatorTop, child.getRight(),
|
||||
separatorTop + dividerHeightPx, mDividerPaint);
|
||||
}
|
||||
}
|
||||
|
||||
private static class SimpleTabColorizer implements SlidingTabLayout.TabColorizer {
|
||||
private int[] mIndicatorColors;
|
||||
private int[] mDividerColors;
|
||||
|
||||
@Override
|
||||
public final int getIndicatorColor(int position) {
|
||||
return mIndicatorColors[position % mIndicatorColors.length];
|
||||
}
|
||||
|
||||
@Override
|
||||
public final int getDividerColor(int position) {
|
||||
return mDividerColors[position % mDividerColors.length];
|
||||
}
|
||||
|
||||
void setIndicatorColors(int... colors) {
|
||||
mIndicatorColors = colors;
|
||||
}
|
||||
|
||||
void setDividerColors(int... colors) {
|
||||
mDividerColors = colors;
|
||||
}
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 386 B |
Loading…
Add table
Add a link
Reference in a new issue