...
 
Commits (4)
......@@ -20,6 +20,7 @@ buildscript {
allprojects {
repositories {
// mavenCentral()
jcenter()
maven { url = 'https://oss.sonatype.org/content/groups/public' }
maven { url "https://maven.google.com" }
......
......@@ -52,7 +52,7 @@ def getVersionName = { ->
}
return stdout.toString().trim()
} catch (ignored) {
return null;
return null
}
}
......@@ -118,6 +118,7 @@ android {
}
dexOptions {
javaMaxHeapSize '2048M'
preDexLibraries = false
}
productFlavors {
}
......@@ -208,14 +209,14 @@ dependencies {
androidTestCompile 'com.squareup.okhttp3:mockwebserver:3.6.0'
// tempat custom dependencies capi-stis, supaya gampang updatenya
// sudah ada ui-android, peta wb, revalidasi (soon)
compile('com.mikepenz:materialdrawer:6.0.2@aar') {
compile('com.mikepenz:materialdrawer:6.0.7@aar') {
transitive = true
}
compile('com.mapbox.mapboxsdk:mapbox-android-sdk:5.0.2@aar') {
transitive = true
}
compile project(':slidingmenu')
compile project(':vsen_p')
// compile project(':vsen_p')
compile 'org.apache.commons:commons-lang3:3.6'
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.android.support:support-v4:26.1.0'
......@@ -231,4 +232,4 @@ dependencies {
// Must be at bottom to prevent dependency collisions
// https://developers.google.com/android/guides/google-services-plugin
apply plugin: 'com.google.gms.google-services'
\ No newline at end of file
apply plugin: 'com.google.gms.google-services'
This diff is collapsed.
......@@ -31,45 +31,34 @@ import com.mikepenz.materialdrawer.model.SectionDrawerItem;
import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem;
import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader;
import com.mikepenz.materialdrawer.util.DrawerImageLoader;
import com.rahadi.vsen.contexts.Vsen;
import com.rahadi.vsen.daos.BlokSensusDao;
import com.rahadi.vsen.daos.CatatanDao;
import com.rahadi.vsen.daos.DsrtDao;
import com.rahadi.vsen.daos.DsrtLogDao;
import com.rahadi.vsen.daos.RutaDao;
import com.rahadi.vsen.listeners.OnSynchronizationCompletedListener;
import com.rahadi.vsen.models.UserModel;
import com.rahadi.vsen.tasks.BSSynchronizationTask;
import com.squareup.picasso.Picasso;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import java.util.ArrayList;
import id.ac.stis.capi.R;
import id.ac.stis.capi.odk.activities.SplashScreenActivity;
import id.ac.stis.capi.collectiva.fragment.CapiFormFragment;
import id.ac.stis.capi.collectiva.preferences.CapiInstancePreferences;
import id.ac.stis.capi.odk.activities.SplashScreenActivity;
import id.ac.stis.capi.odk.database.ItemsetDbAdapter;
import id.ac.stis.capi.odk.listeners.DiskSyncListener;
import id.ac.stis.capi.pemutakhiran.fragments.BSFragment;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.odk.tasks.DiskSyncTask;
import id.ac.stis.capi.petawbdigital.activities.GeoPointMapboxRevoActivity;
import id.ac.stis.capi.petawbdigital.assets.VAR;
import id.ac.stis.capi.petawbdigital.externals.AksesDataOdk;
import id.ac.stis.capi.petawbdigital.fragments.WbFragment;
import id.ac.stis.capi.petawbdigital.models.BlokSensus;
import id.ac.stis.capi.petawbdigital.models.Form;
import id.ac.stis.capi.odk.preferences.GeneralSharedPreferences;
import id.ac.stis.capi.odk.preferences.PreferenceKeys;
import id.ac.stis.capi.revalidasi.fragments.DataDownloadFragment;
import id.ac.stis.capi.revalidasi.notifikasi.GetUuidTask;
import id.ac.stis.capi.odk.tasks.DiskSyncTask;
import timber.log.Timber;
/**
* @author Muhammad Tohir
* edit Mahendri Dwicahyo
* edit Mahendri Dwicahyo
*/
public class CapiMainActivity extends AppCompatActivity implements DiskSyncListener {
......@@ -85,7 +74,6 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
private Drawer result;
private GeneralSharedPreferences prefs;
private CapiFormFragment capiListForms;
private BSFragment bsFragment;
private DataDownloadFragment dataDownloadFragment;
private WbFragment wbFragment;
private Toolbar toolbar;
......@@ -98,7 +86,6 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
toolbar = (Toolbar) findViewById(R.id.toolbar);
capiListForms = new CapiFormFragment();
bsFragment = BSFragment.newInstance();
dataDownloadFragment = DataDownloadFragment.newInstance();
wbFragment = WbFragment.newInstance();
prefs = GeneralSharedPreferences.getInstance();
......@@ -183,37 +170,38 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
pd.setMessage("Logging Out..");
pd.show();
UserModel um = Vsen.getInstance().getUserSession();
new BSSynchronizationTask(null, null).execute(um.getIdUser(), um.getAuthToken(),
new OnSynchronizationCompletedListener<JSONArray>() {
@Override
public void onSynchronizationCompleted(JSONArray result) {
pd.dismiss();
Vsen.getInstance().clearUserSession();
new BlokSensusDao().deleteBlokSensus();
new CatatanDao().deleteCatatan();
new DsrtDao().deleteDsrt();
new DsrtLogDao().deleteDsrtLog();
new RutaDao().deleteRuta();
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
}
@Override
public void onSynchronizationFailed(Exception e) {
pd.dismiss();
Toast.makeText(CapiMainActivity.this, "Gagal Logout", Toast.LENGTH_LONG).show();
}
});
// UserModel um = Vsen.getInstance().getUserSession();
// new BSSynchronizationTask(null, null).execute(um.getIdUser(), um.getAuthToken(),
// new OnSynchronizationCompletedListener<JSONArray>() {
// @Override
// public void onSynchronizationCompleted(JSONArray result) {
// pd.dismiss();
// Vsen.getInstance().clearUserSession();
// new BlokSensusDao().deleteBlokSensus();
// new CatatanDao().deleteCatatan();
// new DsrtDao().deleteDsrt();
// new DsrtLogDao().deleteDsrtLog();
// new RutaDao().deleteRuta();
prefs.reset(PreferenceKeys.KEY_LOGIN_STATUS);
prefs.reset(PreferenceKeys.KEY_USERNAME);
prefs.reset(PreferenceKeys.KEY_PASSWORD);
prefs.reset(PreferenceKeys.KEY_USERGROUP);
prefs.reset(PreferenceKeys.KEY_METADATA_USERGROUP);
String uuid = (String) prefs.get(PreferenceKeys.KEY_UNIQUES);
if (StringUtils.isNotEmpty(uuid))
FirebaseMessaging.getInstance().unsubscribeFromTopic(GetUuidTask.getPureUri(uuid));
startActivity(new Intent(CapiMainActivity.this, SplashScreenActivity.class));
finish();
// }
//
// @Override
// public void onSynchronizationFailed(Exception e) {
// pd.dismiss();
// Toast.makeText(CapiMainActivity.this, "Gagal Logout", Toast.LENGTH_LONG).show();
// }
// });
}
private void initializeDrawer(final Context context, Bundle savedInstanceState) {
......@@ -280,11 +268,11 @@ public class CapiMainActivity extends AppCompatActivity implements DiskSyncListe
@Override
public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
switch ((int) drawerItem.getIdentifier()) {
case MENU_PEMUTAKHIRAN:
// startActivity(new Intent(context, BSActivity.class));
getSupportActionBar().setTitle("Pemutakhiran");
openFragment(bsFragment);
break;
// case MENU_PEMUTAKHIRAN:
//// startActivity(new Intent(context, BSActivity.class));
// getSupportActionBar().setTitle("Pemutakhiran");
// openFragment(bsFragment);
// break;
case MENUSURVEY:
getSupportActionBar().setTitle("Daftar Kuesioner");
......
......@@ -21,9 +21,6 @@ import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
import com.rahadi.vsen.activities.VsenPreferenceActivity;
import com.rahadi.vsen.fragments.VsenPreferenceFragment;
import id.ac.stis.capi.R;
import id.ac.stis.capi.collectiva.ParseXml;
import id.ac.stis.capi.odk.dao.FormsDao;
......@@ -160,13 +157,13 @@ public class CapiInstancePreferences extends AppCompatActivity
startActivity(new Intent(this, KonfigurasiPeta.class));
finish();
break;
case R.id.updating_setting:
Intent i = new Intent(this, VsenPreferenceActivity.class);
i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, VsenPreferenceFragment.class.getName());
i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
startActivity(i);
finish();
break;
// case R.id.updating_setting:
// Intent i = new Intent(this, VsenPreferenceActivity.class);
// i.putExtra(PreferenceActivity.EXTRA_SHOW_FRAGMENT, VsenPreferenceFragment.class.getName());
// i.putExtra(PreferenceActivity.EXTRA_NO_HEADERS, true);
// startActivity(i);
// finish();
// break;
}
}
......
package id.ac.stis.capi.lessthink.activities;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Toast;
import java.util.LinkedHashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.models.FormLabels;
import id.ac.stis.capi.lessthink.models.InstanceValues;
import id.ac.stis.capi.lessthink.views.TableFooterView;
import id.ac.stis.capi.lessthink.views.TableHeaderView;
import id.ac.stis.capi.lessthink.views.TableRowView;
public class ListingInstanceActivity extends AppCompatActivity {
private TableHeaderView tableHeaderView;
private TableRowView tableRowView;
private TableFooterView tableFooterView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_listing_instance);
setSupportActionBar((Toolbar) findViewById(R.id.toolbar));
tableHeaderView = findViewById(R.id.header_view);
tableRowView = findViewById(R.id.row_view);
tableFooterView = findViewById(R.id.footer_view);
Map<String, String> headerList = new LinkedHashMap<>();
headerList.put("no_sls", "No. SLS");
headerList.put("no_bs", "No. BS");
headerList.put("no_bf", "No. BF");
headerList.put("no_nks", "No. NKS");
headerList.put("nama_krt", "Nama KRT");
FormLabels formLabels = new FormLabels("formId", headerList);
tableHeaderView.setColumns(formLabels);
List<InstanceValues> instanceValues = new LinkedList<>();
for (int i = 0; i < 31; i++) {
Map<String, String> rowData = new LinkedHashMap<>();
rowData.put("no_sls", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_bs", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_bf", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("no_nks", (i < 9 ? "00" : "0") + (i + 1));
rowData.put("nama_krt", "Nama KRT " + i);
instanceValues.add(new InstanceValues("instanceId" + i, "formId", rowData));
}
tableRowView.setRows(instanceValues);
tableRowView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(ListingInstanceActivity.this, "Click : " + view.getTag(), Toast.LENGTH_LONG).show();
}
});
}
}
package id.ac.stis.capi.lessthink.listeners;
import android.view.View;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnFooterNavigationListener {
int onGoToNextPage(View v);
int onGoToPrevPage(View v);
}
package id.ac.stis.capi.lessthink.listeners;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnHandlerMovedListener {
void onStartMoving(String key);
void onMoving(String key);
void onStopMoving(String key);
}
package com.rahadi.vsen.listeners;
package id.ac.stis.capi.lessthink.listeners;
import android.view.View;
/**
* Created by Rahadi on 17/11/2017.
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public interface OnRecyclerItemClickListener {
void onItemClick(View v, int position);
}
package id.ac.stis.capi.lessthink.models;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class FormLabels implements Serializable {
private String formId;
private Map<String, String> formLabel;
public FormLabels(String formId, Map<String, String> formLabel) {
this.formId = formId;
this.formLabel = formLabel;
}
public FormLabels putFormLabel(String xPath, String label) {
formLabel.put(xPath, label);
return this;
}
public String getFormId() {
return formId;
}
public Set<String> getXPaths() {
return formLabel.keySet();
}
public int getLabelCount() {
return formLabel.size();
}
public String getFormLabel(String xPath) {
return formLabel.get(xPath);
}
}
package id.ac.stis.capi.lessthink.models;
import java.io.Serializable;
import java.util.Map;
import java.util.Set;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class InstanceValues implements Serializable {
private String instanceId;
private String formId;
private Map<String, String> instanceValue;
public InstanceValues(String instanceId, String formId, Map<String, String> instanceValue) {
this.instanceId = instanceId;
this.formId = formId;
this.instanceValue = instanceValue;
}
public InstanceValues putInstanceValue(String xPath, String value) {
instanceValue.put(xPath, value);
return this;
}
public String getInstanceId() {
return instanceId;
}
public String getFormId() {
return formId;
}
public Set<String> getXPaths() {
return instanceValue.keySet();
}
public int getValueCount() {
return instanceValue.size();
}
public String getInstanceValue(String xPath) {
return instanceValue.get(xPath);
}
}
......@@ -10,7 +10,7 @@ import java.util.List;
import java.util.Set;
import id.ac.stis.capi.lessthink.listeners.DependenciesResolverListener;
import id.ac.stis.capi.lessthink.logics.DependencyDetails;
import id.ac.stis.capi.lessthink.models.DependencyDetails;
import id.ac.stis.capi.odk.application.Collect;
import id.ac.stis.capi.odk.dao.FormsDao;
import id.ac.stis.capi.odk.dto.Form;
......
package id.ac.stis.capi.lessthink.utils;
import org.javarosa.xform.parse.XFormParser;
import org.kxml2.kdom.Document;
import org.kxml2.kdom.Element;
import org.kxml2.kdom.Node;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.xpath.XPath;
import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathFactory;
import id.ac.stis.capi.lessthink.models.FormLabels;
import id.ac.stis.capi.lessthink.models.InstanceValues;
import timber.log.Timber;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class XmlUtils {
public static List<String> getInstanceXPathList(File file, String startingNode) {
InputStream is;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e1) {
Timber.e(e1);
throw new IllegalStateException(e1);
}
InputStreamReader isr;
try {
isr = new InputStreamReader(is, "UTF-8");
} catch (UnsupportedEncodingException uee) {
Timber.w(uee, "Trying default encoding as UTF 8 encoding unavailable");
isr = new InputStreamReader(is);
}
Document doc;
try {
doc = XFormParser.getXMLDocument(isr);
} catch (IOException e) {
Timber.e(e, "Unable to parse XML document %s", file.getAbsolutePath());
throw new IllegalStateException("Unable to parse XML document", e);
} finally {
try {
isr.close();
} catch (IOException e) {
Timber.w("%s error closing from reader", file.getAbsolutePath());
}
}
String html = doc.getRootElement().getNamespace();
Element head = doc.getRootElement().getElement(html, "head");
Element model = getChildElement(head, "model");
Element cur = getChildElement(model, "instance");
int idx = cur.getChildCount();
int i;
for (i = 0; i < idx; ++i) {
if (cur.isText(i)) {
continue;
}
if (cur.getType(i) == Node.ELEMENT) {
break;
}
}
if (i < idx) {
cur = cur.getElement(i);
return getXPathByElement(cur);
} else {
throw new IllegalStateException(file.getAbsolutePath() + " could not be parsed");
}
}
public static FormLabels getFromLabels(String formId, File file, List<String> xPaths) {
Map<String, String> titles = new LinkedHashMap<>();
InputStream is;
try {
is = new FileInputStream(file);
} catch (FileNotFoundException e1) {
Timber.e(e1);
throw new IllegalStateException(e1);
}
InputStreamReader isr;
try {
isr = new InputStreamReader(is, "UTF-8");
} catch (UnsupportedEncodingException uee) {
Timber.w(uee, "Trying default encoding as UTF 8 encoding unavailable");
isr = new InputStreamReader(is);
}
Document doc;
try {
doc = XFormParser.getXMLDocument(isr);
} catch (IOException e) {
Timber.e(e, "Unable to parse XML document %s", file.getAbsolutePath());
throw new IllegalStateException("Unable to parse XML document", e);
} finally {
try {
isr.close();
} catch (IOException e) {
Timber.w("%s error closing from reader", file.getAbsolutePath());
}
}
String html = doc.getRootElement().getNamespace();
Element body = doc.getRootElement().getElement(html, "body");
for (int i = 0; i < body.getChildCount(); i++) {
if (body.isText(i)) {
continue;
}
if (body.getType(i) == Node.ELEMENT) {
Element curr = body.getElement(i);
String ref = getAttributeValue(curr, "ref");
if (ref != null) {
if (xPaths.contains(ref)) {
Element label = getChildElement(curr, "label");
if (label != null) {
titles.put(ref, getText(label));
}
}
}
}
}
return new FormLabels(formId, titles);
}
public static InstanceValues getInstanceValues(String instanceId, File file, FormLabels formLabels) {
Map<String, String> values = new LinkedHashMap<>();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(false);
try {
DocumentBuilder builder = factory.newDocumentBuilder();
org.w3c.dom.Document doc = builder.parse(file);
XPathFactory xPathFactory = XPathFactory.newInstance();
XPath xPath = xPathFactory.newXPath();
Set<String> xPaths = formLabels.getXPaths();
for (String xPathString : xPaths) {
XPathExpression expression = xPath.compile(xPathString);
Object res = expression.evaluate(doc, XPathConstants.NODE);
Node node = (Node) res;
values.put(xPathString, node.getText(0));
}
} catch (Throwable throwable) {
Timber.e(throwable);
}
return new InstanceValues(instanceId, formLabels.getFormId(), values);
}
private static List<String> getXPathByElement(Element element) {
List<String> target = new ArrayList<>();
getXPathToTarget(target, element, "/" + element.getName());
return target;
}
private static void getXPathToTarget(List<String> target, Element element, String currXPath) {
if (element.getChildCount() == 0 || (element.getChildCount() == 1 && element.isText(0))) {
target.add(currXPath + "/" + element.getName());
return;
}
for (int i = 0; i < element.getChildCount(); i++) {
getXPathToTarget(target, element.getElement(i),
currXPath + "/" + element.getName());
}
}
private static Element getChildElement(Element parent, String childName) {
for (int i = 0; i < parent.getChildCount(); i++) {
if (parent.getType(i) == Node.ELEMENT) {
if (parent.getElement(i).getName().equalsIgnoreCase(childName)) {
return parent.getElement(i);
}
}
}
return null;
}
private static String getText(Element parent) {
for (int i = 0; i < parent.getChildCount(); i++) {
if (parent.isText(i)) {
return parent.getText(i);
}
}
return null;
}
private static String getAttributeValue(Element element, String attributeName) {
for (int i = 0; i < element.getAttributeCount(); i++) {
if (element.getAttributeName(i).equalsIgnoreCase(attributeName)) {
return element.getAttributeValue(i);
}
}
return null;
}
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;
import id.ac.stis.capi.R;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class ListingTableView extends View {
public static final int COLUMN_TYPE_HEADER = 1;
public static final int COLUMN_TYPE_BODY = 2;
public static final int SEP_TYPE_HEADER = 3;
public static final int SEP_TYPE_BODY = 4;
private static final int KEY_COLUMN_IDX = 0;
/*
The HashMap<String, String> should be in the form of:
key: header key
value: header name value
*/
private HashMap<String, String> headerList;
/*
ArrayList<> denotes as rows.
The HashMap<String, String> should be in the form of:
key: header key
value: row value
*/
private ArrayList<HashMap<String, String>> rowData;
private LinearLayout headerContainer, rowContainer;
public ListingTableView(Context context) {
super(context);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
}
public ListingTableView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}
public void init(HashMap<String, String> headerList, ArrayList<HashMap<String, String>> rowData) {
this.headerList = headerList;
this.rowData = rowData;
init();
}
private void init() {
// TODO: 06/06/2018 Proper exception
// if (headerList.size() != rowData.size()) {
// throw new DimensionInvalidException("Number of Column is Invalid");
// }
View v = LayoutInflater.from(getContext()).inflate(R.layout.view_listing_table,
null, false);
headerContainer = v.findViewById(R.id.header_container);
rowContainer = v.findViewById(R.id.row_container);
// Creates Header
int headerIdx = 0;
Set<String> headerKeySet = headerList.keySet();
for (String headerKey : headerKeySet) {
TextView header = createNewColumn(COLUMN_TYPE_HEADER, headerKey,
headerList.get(headerKey), headerIdx);
headerContainer.addView(header);
View separator = createNewSeparator(SEP_TYPE_HEADER, headerKey, headerIdx);
headerContainer.addView(separator);
headerIdx++;
}
// Creates Row
for (int i = 0; i < rowData.size(); i++) {
LinearLayout row = createNewRow(rowData.get(i), i);
rowContainer.addView(row);
}
}
private TextView createNewColumn(int type, String key, String value, int columnIdx) {
TextView column = new TextView(getContext());
column.setTag(key);
column.setTag(KEY_COLUMN_IDX, columnIdx);
column.setText(value);
switch (type) {
case COLUMN_TYPE_HEADER:
column.setContentDescription("h-" + columnIdx);
return column;
case COLUMN_TYPE_BODY:
column.setContentDescription("b-" + columnIdx);
column.setTag(key);
return column;
}
return null;
}
private View createNewSeparator(int type, String key, int columnIdx) {
View separator = new View(getContext());
separator.setTag(key);
separator.setTag(KEY_COLUMN_IDX, columnIdx);
switch (type) {
case SEP_TYPE_HEADER:
separator.setContentDescription("sh-" + columnIdx);
final TextView column = headerContainer.findViewWithTag(key);
column.measure(0, 0);
final int oriWidth = column.getMeasuredWidth();
final ArrayList<View> rowInBodyList = new ArrayList<>();
headerContainer.findViewsWithText(rowInBodyList, "b-" + columnIdx,
FIND_VIEWS_WITH_CONTENT_DESCRIPTION);
separator.setOnTouchListener(new View.OnTouchListener() {
int prevX;
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
view.getParent().requestDisallowInterceptTouchEvent(true);
switch (motionEvent.getAction()) {
case MotionEvent.ACTION_DOWN:
prevX = (int) motionEvent.getRawX();
return true;
case MotionEvent.ACTION_MOVE:
if (column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
column.setWidth(column.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
for (View rowInBody : rowInBodyList) {
((TextView) rowInBody).setWidth(rowInBody.getMeasuredWidth()
+ (int) motionEvent.getRawX() - prevX);
}
prevX = (int) motionEvent.getRawX();
}
return true;
}
return false;
}
});
return separator;
case SEP_TYPE_BODY:
separator.setContentDescription("sb-" + columnIdx);
return separator;
}
return null;
}
private LinearLayout createNewRow(HashMap<String, String> data, int rowIdx) {
LinearLayout row = new LinearLayout(getContext());
row.setContentDescription("r-" + rowIdx);
row.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) row.getLayoutParams();
params.width = LinearLayout.LayoutParams.WRAP_CONTENT;
params.height = LinearLayout.LayoutParams.WRAP_CONTENT;
row.setLayoutParams(params);
Set<String> dataKeySet = data.keySet();
for (String dataKey : dataKeySet) {
int idxPosition = (Integer) headerContainer.findViewWithTag(dataKey).getTag(KEY_COLUMN_IDX);
TextView column = createNewColumn(COLUMN_TYPE_BODY, dataKey, data.get(dataKey), idxPosition);
row.addView(column);
View separator = createNewSeparator(SEP_TYPE_BODY, dataKey, idxPosition);
headerContainer.addView(separator);
}
return row;
}
// final HorizontalScrollView header = findViewById(R.id.header_layout);
// header.setOnTouchListener(new View.OnTouchListener() {
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// return true;
// }
// });
//
// final TextView column1 = findViewById(R.id.column_1);
// column1.measure(0, 0);
//
// final TextView row1 = findViewById(R.id.row_1);
//
// final View dragme = findViewById(R.id.dragme);
// final int oriWidth = column1.getMeasuredWidth();
// dragme.setOnTouchListener(new View.OnTouchListener() {
//
// int prevX;
//
// @Override
// public boolean onTouch(View view, MotionEvent motionEvent) {
// view.getParent().requestDisallowInterceptTouchEvent(true);
// switch (motionEvent.getAction()) {
// case MotionEvent.ACTION_DOWN:
// prevX = (int) motionEvent.getRawX();
// return true;
// case MotionEvent.ACTION_MOVE:
// if(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX >= oriWidth) {
// column1.setWidth(column1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// row1.setWidth(row1.getMeasuredWidth() + (int) motionEvent.getRawX() - prevX);
// prevX = (int) motionEvent.getRawX();
// }
// return true;
// }
// return false;
// }
// });
//
// final HorizontalScrollView scrollView = findViewById(R.id.scroll_view);
//
// scrollView.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() {
// @Override
// public void onScrollChanged() {
// header.scrollTo(scrollView.getScrollX(), 0);
// }
// });
}
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.HorizontalScrollView;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class ObservableHorizontalScrollView extends HorizontalScrollView {
public interface OnScrollListener {
public void onScrollChanged(ObservableHorizontalScrollView scrollView, int x, int y, int oldX, int oldY);
public void onEndScroll(ObservableHorizontalScrollView scrollView);
}
private boolean mIsScrolling;
private boolean mIsTouching;
private Runnable mScrollingRunnable;
private OnScrollListener mOnScrollListener;
public ObservableHorizontalScrollView(Context context) {
this(context, null, 0);
}
public ObservableHorizontalScrollView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
public ObservableHorizontalScrollView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@Override
public boolean onTouchEvent(MotionEvent ev) {
int action = ev.getAction();
if (action == MotionEvent.ACTION_MOVE) {
mIsTouching = true;
mIsScrolling = true;
} else if (action == MotionEvent.ACTION_UP) {
if (mIsTouching && !mIsScrolling) {
if (mOnScrollListener != null) {
mOnScrollListener.onEndScroll(this);
}
}
mIsTouching = false;
}
return super.onTouchEvent(ev);
}
@Override
protected void onScrollChanged(int x, int y, int oldX, int oldY) {
super.onScrollChanged(x, y, oldX, oldY);
if (Math.abs(oldX - x) > 0) {
if (mScrollingRunnable != null) {
removeCallbacks(mScrollingRunnable);
}
mScrollingRunnable = new Runnable() {
public void run() {
if (mIsScrolling && !mIsTouching) {
if (mOnScrollListener != null) {
mOnScrollListener.onEndScroll(ObservableHorizontalScrollView.this);
}
}
mIsScrolling = false;
mScrollingRunnable = null;
}
};
postDelayed(mScrollingRunnable, 200);
}
if (mOnScrollListener != null) {
mOnScrollListener.onScrollChanged(this, x, y, oldX, oldY);
}
}
public OnScrollListener getOnScrollListener() {
return mOnScrollListener;
}
public void setOnScrollListener(OnScrollListener mOnEndScrollListener) {
this.mOnScrollListener = mOnEndScrollListener;
}
}
\ No newline at end of file
package id.ac.stis.capi.lessthink.views;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.PorterDuff;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
import id.ac.stis.capi.R;
import id.ac.stis.capi.lessthink.listeners.OnFooterNavigationListener;
/**
* Author : Rahadi Jalu
* Email : 14.8325@stis.ac.id
* Company: Politeknik Statistika STIS
*/
public class TableFooterView extends RelativeLayout implements View.OnClickListener {
private ImageView addButton;
private TextView currPage;
private LinearLayout pageIndicator, navigationWrapper;
private int textSize, componentColor, footerColor, currentPage, pageCount;
private OnFooterNavigationListener onFooterNavigationListener;
public TableFooterView(Context context, AttributeSet attrs) {
super(context, attrs);
this.textSize = 12;
this.componentColor = ContextCompat.getColor(getContext(), R.color.white);
this.footerColor = ContextCompat.getColor(getContext(), R.color.accent);
this.currentPage = 1;
this.pageCount = 1;
if (getId() == NO_ID) {
setId(R.id.row_view_footer_id);
}
TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TableFooterView,
0, 0);
try {
setTextSize(a.getDimensionPixelSize(R.styleable.TableFooterView_footerTextSize, getTextSize()));
setComponentColor(a.getColor(R.styleable.TableFooterView_footerComponentColor, getComponentColor()));
setFooterColor(a.getColor(R.styleable.TableFooterView_footerColor, getFooterColor()));
} finally {
a.recycle();
}
setBackgroundColor(getFooterColor());
this.pageIndicator = new LinearLayout(getContext());
RelativeLayout.LayoutParams pageIndicatorParams = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
pageIndicatorParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT, RelativeLayout.TRUE);
pageIndicatorParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
pageIndicatorParams.leftMargin = 10;
pageIndicator.setLayoutParams(pageIndicatorParams);
pageIndicator.setPadding(15, 15, 15, 15);
pageIndicator.setOrientation(LinearLayout.VERTICAL);
addView(pageIndicator);
TextView page = new TextView(getContext());
page.setTextColor(getComponentColor());
page.setTextSize(TypedValue.COMPLEX_UNIT_SP, getTextSize());
page.setText("Page");
pageIndicator.addView(page);
currPage = new TextView(getContext());
currPage.setTextColor(getComponentColor());
currPage.setTextSize(TypedValue.COMPLEX_UNIT_SP, getTextSize());
currPage.setText("1 of 1");
pageIndicator.addView(currPage);
this.navigationWrapper = new LinearLayout(getContext());
RelativeLayout.LayoutParams navigationWrapperParams = new LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
navigationWrapperParams.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
navigationWrapperParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
navigationWrapper.setLayoutParams(navigationWrapperParams);
addView(navigationWrapper);
int sizeForButtons = Math.round(TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
40, getResources().getDisplayMetrics()));
// ImageView prevButton = new ImageView(new ContextThemeWrapper(getContext(),
// R.style.Widget_AppCompat_Button_Borderless), null, 0);
ImageView prevButton = new ImageView(getContext(), null, 0);
LinearLayout.LayoutParams prevButtonParams = new LinearLayout.LayoutParams(sizeForButtons, sizeForButtons);
prevButtonParams.rightMargin = 10;
prevButton.setLayoutParams(prevButtonParams);
prevButton.setId(R.id.footer_view_prev_button);
prevButton.setPadding(15, 15, 15, 15);
prevButton.setBackground(ContextCompat.getDrawable(getContext(), getSelectableResourceId()));
prevButton.setImageResource(R.drawable.ic_keyboard_arrow_left);
prevButton.setColorFilter(getComponentColor(), PorterDuff.Mode.MULTIPLY);
prevButton.setOnClickListener(this);
navigationWrapper.addView(prevButton);
// ImageView nextButton = new ImageView(new ContextThemeWrapper(getContext(),
// R.style.Widget_AppCompat_Button_Borderless), null, 0);
ImageView nextButton = new ImageView(getContext(), null, 0);
LinearLayout.LayoutParams nextButtonParams = new LinearLayout.LayoutParams(sizeForButtons, sizeForButtons);
nextButtonParams.leftMargin = 10;
nextButton.setLayoutParams(nextButtonParams);
nextButton.setId(R.id.footer_view_next_button);
nextButton.setPadding(15, 15, 15, 15);
nextButton.setBackground(ContextCompat.getDrawable(getContext(), getSelectableResourceId()));
nextButton.setImageResource(R.drawable.ic_keyboard_arrow_right);
nextButton.setColorFilter(getComponentColor(), PorterDuff.Mode.MULTIPLY);
nextButton.setOnClickListener(this);
navigationWrapper.addView(nextButton);
// this.addButton = new ImageView(new ContextThemeWrapper(getContext(),
// R.style.Widget_AppCompat_Button_Borderless), null, 0);
this.addButton = new ImageView(getContext(), null, 0);
addButton.setId(R.id.footer_view_add_button);
RelativeLayout.LayoutParams addButtonParams = new LayoutParams(sizeForButtons, sizeForButtons);
addButtonParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT, RelativeLayout.TRUE);
addButtonParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
addButtonParams.rightMargin = 10;
addButton.setLayoutParams(addButtonParams);
addButton.setPadding(15, 15, 15, 15);
addButton.setBackground(ContextCompat.getDrawable(getContext(), getSelectableResourceId()));
addButton.setImageResource(R.drawable.ic_add);
// addButton.setColorFilter(getComponentColor(), PorterDuff.Mode.MULTIPLY);
addButton.setOnClickListener(this);
addView(addButton);
}
public void setPageCountInfo(int pageCount) {
this.pageCount = pageCount;
currPage.setText(currentPage + " of " + pageCount);
}
public void setOnFooterNavigationListener(OnFooterNavigationListener onFooterNavigationListener) {
this.onFooterNavigationListener = onFooterNavigationListener;
}
public int getTextSize() {
return textSize;
}
public void setTextSize(int textSize) {
this.textSize = textSize;
invalidate();
requestLayout();
}
public int getComponentColor() {
return componentColor;
}
public void setComponentColor(int componentColor) {
this.componentColor = componentColor;
invalidate();
requestLayout();
}
public int getFooterColor() {
return footerColor;
}
public void setFooterColor(int footerColor) {
this.footerColor = footerColor;
invalidate();
requestLayout();
}
@Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.footer_view_add_button:
Toast.makeText(getContext(), "ADD", Toast.LENGTH_LONG).show();
break;
case R.id.footer_view_prev_button:
// Toast.makeText(getContext(), "PREV", Toast.LENGTH_LONG).show();
if (onFooterNavigationListener != null) {
this.currentPage = onFooterNavigationListener.onGoToPrevPage(view);
}
currPage.setText(currentPage + " of " + pageCount);
break;
case R.id.footer_view_next_button:
// Toast.makeText(getContext(), "NEXT", Toast.LENGTH_LONG).show();
if (onFooterNavigationListener != null) {
this.currentPage = onFooterNavigationListener.onGoToNextPage(view);
}
currPage.setText(currentPage + " of " + pageCount);
break;
}
}