Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
mkulesh committed Oct 13, 2018
1 parent 323d5d2 commit b71cdfc
Show file tree
Hide file tree
Showing 261 changed files with 8,273 additions and 0 deletions.
39 changes: 39 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 27
buildToolsVersion "27.0.3"

defaultConfig {
applicationId "com.mkulesh.onpc"
minSdkVersion 14
targetSdkVersion 27
versionCode 1
versionName "1.0"
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
applicationVariants.all { variant ->
variant.outputs.each { output ->
def file = output.outputFile
output.outputFile = new File(file.parent, "onpc-" + defaultConfig.versionName + ".apk")
}
}
}
}

lintOptions {
checkReleaseBuilds false
abortOnError false
disable "RtlHardcoded", "RtlSymmetry", "RtlEnabled"
}
}

dependencies {
compile 'com.android.support:support-v4:27.1.0'
compile 'com.android.support:appcompat-v7:27.1.0'
compile 'com.android.support:design:27.1.0'
}
25 changes: 25 additions & 0 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Add project specific ProGuard rules here.
# By default, the flags in this file are appended to flags specified
# in /home/andrey/Android/Sdk/tools/proguard/proguard-android.txt
# You can edit the include path and order by changing the proguardFiles
# directive in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# Add any project specific keep options here:

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
41 changes: 41 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mkulesh.onpc"
android:installLocation="auto"
xmlns:tools="http://schemas.android.com/tools"
tools:ignore="UnusedAttribute,AllowBackup">

<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:allowClearUserData="true"
android:hardwareAccelerated="true"
android:icon="@mipmap/ic_launcher"
android:roundIcon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppBaseThemeLight"
android:description="@string/app_description">

<activity
android:name="com.mkulesh.onpc.MainActivity"
android:label="@string/app_name"
android:windowSoftInputMode="stateHidden">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<activity
android:name="com.mkulesh.onpc.SettingsActivity"
android:label="@string/action_app_settings"
android:parentActivityName="com.mkulesh.onpc.MainActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.mkulesh.onpc.MainActivity" />
</activity>

</application>

</manifest>
73 changes: 73 additions & 0 deletions app/src/main/java/com/mkulesh/onpc/BaseFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.mkulesh.onpc;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.widget.AppCompatImageButton;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.mkulesh.onpc.utils.Utils;

abstract public class BaseFragment extends Fragment
{
/**
* Constants used to save/restore the instance state.
*/
public static final String FRAGMENT_NUMBER = "fragment_number";
public static final String SERVER_NAME = "server_name";
public static final String SERVER_PORT = "server_port";

protected MainActivity activity;
protected SharedPreferences preferences;
protected View rootView = null;
protected int fragmentNumber = -1;

public BaseFragment()
{
// Empty constructor required for fragment subclasses
}

public void initializeFragment(LayoutInflater inflater, ViewGroup container, int layoutId)
{
activity = (MainActivity) getActivity();
preferences = PreferenceManager.getDefaultSharedPreferences(activity);
rootView = inflater.inflate(layoutId, container, false);
Bundle args = getArguments();
fragmentNumber = args != null ? args.getInt(FRAGMENT_NUMBER) : 0;
}

public void update(final State state)
{
if (state == null || !state.isOn())
{
updateStandbyView(state);
}
else
{
updateActiveView(state);
}
}

protected abstract void updateStandbyView(@Nullable final State state);

protected abstract void updateActiveView(@NonNull final State state);

protected void setButtonEnabled(AppCompatImageButton b, boolean isEnabled)
{
b.setEnabled(isEnabled);
Utils.setImageButtonColorAttr(activity, b,
b.isEnabled() ? R.attr.colorButtonEnabled : R.attr.colorButtonDisabled);
}

protected void setButtonSelected(AppCompatImageButton b, boolean isSelected)
{
b.setSelected(isSelected);
Utils.setImageButtonColorAttr(activity, b,
b.isSelected() ? R.attr.colorAccent : R.attr.colorButtonEnabled);
}
}
97 changes: 97 additions & 0 deletions app/src/main/java/com/mkulesh/onpc/DeviceFragment.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
package com.mkulesh.onpc;

import android.annotation.SuppressLint;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

public class DeviceFragment extends BaseFragment implements View.OnClickListener
{
private ImageView deviceCover = null;

public DeviceFragment()
{
// Empty constructor required for fragment subclasses
}

@SuppressLint("SetTextI18n")
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
{
initializeFragment(inflater, container, R.layout.device_fragment);

final Button buttonServerConnect = rootView.findViewById(R.id.device_connect);
buttonServerConnect.setOnClickListener(this);

((EditText) rootView.findViewById(R.id.device_name)).setText(preferences.getString(
DeviceFragment.SERVER_NAME, "onkyo"));
((EditText) rootView.findViewById(R.id.device_port)).setText(Integer.toString(preferences.getInt(
DeviceFragment.SERVER_PORT, 60128)));

deviceCover = rootView.findViewById(R.id.device_cover);

update(null);
return rootView;
}

@Override
public void onClick(View v)
{
if (v.getId() == R.id.device_connect)
{
final String serverName = ((EditText) rootView.findViewById(R.id.device_name)).getText().toString();
final String serverPortStr = ((EditText) rootView.findViewById(R.id.device_port)).getText()
.toString();
final int serverPort = Integer.parseInt(serverPortStr);
if (activity.connectToServer(serverName, serverPort))
{
SharedPreferences.Editor prefEditor = preferences.edit();
prefEditor.putString(SERVER_NAME, serverName);
prefEditor.putInt(SERVER_PORT, serverPort);
prefEditor.commit();
}
}
}

@Override
protected void updateStandbyView(@Nullable final State state)
{
updateDeviceCover(state);
}

@Override
protected void updateActiveView(@NonNull final State state)
{
updateDeviceCover(state);

if (!state.deviceProperties.isEmpty())
{
((TextView) rootView.findViewById(R.id.device_brand)).setText(state.deviceProperties.get("brand"));
((TextView) rootView.findViewById(R.id.device_model)).setText(state.deviceProperties.get("model"));
((TextView) rootView.findViewById(R.id.device_year)).setText(state.deviceProperties.get("year"));
((TextView) rootView.findViewById(R.id.device_firmware)).setText(state.deviceProperties.get("firmwareversion"));
}
}

private void updateDeviceCover(@Nullable final State state)
{
if (state != null && state.deviceCover != null)
{
deviceCover.setVisibility(View.VISIBLE);
deviceCover.setImageBitmap(state.deviceCover);
}
else
{
deviceCover.setVisibility(View.GONE);
deviceCover.setImageBitmap(null);
}
}
}
Loading

0 comments on commit b71cdfc

Please sign in to comment.