Skip to content

Commit

Permalink
Adding user tip to open config
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbrailo committed Mar 31, 2019
1 parent eb31332 commit 7437955
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 15 deletions.
11 changes: 9 additions & 2 deletions app/src/main/java/com/nicobrailo/pianoli/AppConfigTrigger.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,21 @@
class AppConfigTrigger {
public interface AppConfigCallback {
void onConfigOpenRequested();
void onShowConfigTooltip();
}

private static final int CONFIG_TRIGGER_COUNT = 2;
private static final Set<Integer> BLACK_KEYS = new HashSet<>(Arrays.asList(1, 3, 7, 9, 11, 15));
private final AppCompatActivity activity;
private Set<Integer> pressedConfigKeys = new HashSet<>();
private Integer nextKeyPress;
private AppConfigCallback cb;
private AppConfigCallback cb = null;
private boolean tooltip_shown = false;


AppConfigTrigger(AppCompatActivity activity) {
nextKeyPress = getNextExpectedKey();
this.activity = activity;
this.cb = null;
}

void setConfigRequestCallback(AppConfigCallback cb) {
Expand Down Expand Up @@ -72,6 +74,11 @@ public void onCompletion(MediaPlayer mediaPlayer) {
}

void onKeyPress(int key_idx) {
if (!tooltip_shown) {
tooltip_shown = true;
cb.onShowConfigTooltip();
}

if (key_idx == nextKeyPress) {
pressedConfigKeys.add(key_idx);
if (pressedConfigKeys.size() == CONFIG_TRIGGER_COUNT) {
Expand Down
24 changes: 11 additions & 13 deletions app/src/main/java/com/nicobrailo/pianoli/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
package com.nicobrailo.pianoli;

import android.app.ActivityManager;
import android.content.Context;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.support.annotation.RequiresApi;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity implements AppConfigTrigger.AppConfigCallback {

Expand All @@ -41,14 +33,13 @@ protected void onCreate(Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
} catch (Exception e) {}

try {
getSupportActionBar().hide();
} catch (Exception e) {}
if (getSupportActionBar() != null) getSupportActionBar().hide();

try {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
} catch (Exception e) {}

@SuppressLint("InflateParams")
final View view = getLayoutInflater().inflate(R.layout.activity_main, null);
setContentView(view);
((PianoCanvas) view.findViewById(R.id.piano_canvas)).setConfigRequestCallback(this);
Expand Down Expand Up @@ -102,4 +93,11 @@ public void onConfigOpenRequested() {
findViewById(R.id.config_layout).bringToFront();
findViewById(R.id.config_layout).setVisibility(View.VISIBLE);
}

@Override
public void onShowConfigTooltip() {
final String msg = "Press and hold config icons on black keys to exit.";
Toast toast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_LONG);
toast.show();
}
}

0 comments on commit 7437955

Please sign in to comment.