Ejemplo n.º 1
0
 def __init__(self, clock, handler):
     """
     on_tick: function called per tick
     handler: Android os Handler, tied to application's main thread.
     """
     self.clock = clock
     self.handler = handler
     Log.i('TimeUpdateTask', 'initialized')
Ejemplo n.º 2
0
 def write(self, s):
     for line in s.splitlines(
     ):  # "".splitlines() == [], so nothing will be logged.
         line = line or " "  # Empty lines are droped by logcat, so pass a single space.
         while line:
             Log.println(self.level, self.tag, line[:MAX_LINE_LEN])
             line = line[MAX_LINE_LEN:]
     return len(s)
Ejemplo n.º 3
0
 def _start_timer(self):
     """
     Starts the timer
     """
     Log.i('BaseClock', 'called _start_timer()')
     self.start_time_millis = SystemClock.uptimeMillis()
     self.time_handler.removeCallbacks(self.time_update_task)
     self.time_handler.postDelayed(self.time_update_task, TIMER_DELAY)
Ejemplo n.º 4
0
    def restart(self):
        Log.i('BaseClock', 'called restart()')
        self.time_handler.removeCallbacks(self.time_update_task)
        self.state = 'new'
        self.turn = None
        self._reset_timers()

        # Update UI
        self._application.update_ui_state()
Ejemplo n.º 5
0
    def write(self, s):
        if sys.version_info[0] < 3 and isinstance(s, str):
            u = s.decode(self.encoding, self.errors)
        else:
            u = s

        for line in u.splitlines():  # "".splitlines() == [], so nothing will be logged.
            line = line or " "  # Empty log messages are ignored.
            while line:
                Log.println(self.level, self.tag, line[:MAX_LINE_LEN])
                line = line[MAX_LINE_LEN:]

        return len(s)
Ejemplo n.º 6
0
    def on_switch_click(self, player):
        Log.i(
            'BaseClock',
            'called on_switch_player(%s), self.state:%s, self.turn:%s' %
            (player, self.state, self.turn))
        # Starts the clock if game hasn't started yet.
        if self.state == 'new':
            self.turn = 'w' if player == 'b' else 'b'
            self.state = 'active'
            self._start_timer()
            self._turn_switch(-1, self._turn_ind())

            # Update UI
            self._application.update_ui_state()

        # Switches the active clock
        elif self.state == 'active':
            Log.i('BaseClock', 'in active branch')
            if player == 'w' and self.turn == 'w':
                Log.i('BaseClock', 'switching to black')
                self.turn = 'b'
                self._turn_switch(1 - self._turn_ind(), self._turn_ind())
            elif player == 'b' and self.turn == 'b':
                Log.i('BaseClock', 'switching to white')
                self.turn = 'w'
                self._turn_switch(1 - self._turn_ind(), self._turn_ind())

            # Update UI
            self._application.update_ui_state()
Ejemplo n.º 7
0
    def __init__(self, application):

        # call for updating ui
        self._application = application

        # possible values of state = ['new', 'active', 'paused', 'finished']
        self.state = 'new'

        self.turn = None

        # time control
        self.time = [None, None]
        self.delay = [None, None]

        # timer task
        self.start_time_millis = None
        self.time_handler = Handler()
        self.time_update_task = TimeUpdateTask(self, self.time_handler)

        Log.i('BaseClock', 'initialized')
Ejemplo n.º 8
0
 def setUp(self):
     from android.util import Log
     Log.i(*self.get_marker())
     self.expected_log = []
Ejemplo n.º 9
0
 def restart_clicked(self):
     Log.i('MyApplication', 'called restart_clicked()')
     self.clock.restart()
Ejemplo n.º 10
0
 def pause_or_resume_clicked(self):
     Log.i('MyApplication', 'called pause_clicked()')
     self.clock.pause_or_resume()
Ejemplo n.º 11
0
def dream(model, context, array, steps, step_size):
    iterations = steps
    Log.d("Steps", str(steps))
    Log.d("Step Size", str(step_size))

    class StartRunnable(dynamic_proxy(Runnable)):
        def run(self):
            global dialog
            dialog = DreamDialog(context)
            dialog.setCanceledOnTouchOutside(False)
            dialog.create()
            dialog.show()

            window = dialog.getWindow()
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                             WindowManager.LayoutParams.WRAP_CONTENT)

            dialog.setContentSize(iterations)
            dialog.setText("0 / " + str(iterations))
            dialog.updateProgress(0)

    class UpdateRunnable(dynamic_proxy(Runnable)):
        def __init__(self, progress):
            super(UpdateRunnable, self).__init__()
            self.progress = progress

        def run(self):
            global dialog
            dialog.setText(str(self.progress) + " / " + str(iterations))
            dialog.updateProgress(self.progress)

    class EndRunnable(dynamic_proxy(Runnable)):
        def run(self):
            global dialog
            dialog.dismiss()

    context.runOnUiThread(StartRunnable())

    stream = io.BytesIO(bytes(array))
    array = cv2.imdecode(np.fromstring(stream.read(), np.uint8),
                         cv2.IMREAD_COLOR)
    array = cv2.cvtColor(array, cv2.COLOR_BGR2RGB)
    Log.d("Size", str(array.shape))
    size = (array.shape[1], array.shape[0])
    array = ((array / 127.5) - 1.0).astype(np.float32)
    array = np.expand_dims(array, axis=0)
    for i in range(iterations):
        Log.d("Iteration", str(i))
        if i % 5 == 0:
            multiplier = np.random.uniform(0.5, 1.5)
            array = tf.image.resize(array, (
                int((256 * multiplier)),
                int((256 * multiplier)),
            ))

        with tf.GradientTape() as tape:
            tape.watch(array)
            out = model(array)
            loss = 0
            for l in out:
                loss += tf.reduce_sum(l)

        grads = tape.gradient(loss, array)
        grads /= tf.math.reduce_std(grads) + 1e-8

        array = array + grads * step_size
        array = tf.clip_by_value(array, -1, 1)
        context.runOnUiThread(UpdateRunnable((i + 1)))

    array = array.numpy()[0]
    array = cv2.resize(array, size)
    array = ((1.0 + array) * 127.5).astype(np.uint8)
    array = cv2.cvtColor(array, cv2.COLOR_RGB2BGR)
    _, array = cv2.imencode('.png', array)
    context.runOnUiThread(EndRunnable())
    return array.tobytes()
Ejemplo n.º 12
0
 def onClick(self, v: android.view.View) -> void:
     Log.i("TESTAPP", "Push the button")
     self.text_view.setText(self.text_view.getText().toString() +
                            "\nStop touching me!\n")
     Log.i("TESTAPP", "Text updated")
Ejemplo n.º 13
0
		task.execute();

	}

	public String getLeaderData() {
		String response = "";
		try {
			HttpClient httpclient = new DefaultHttpClient();
			String connect = MyConsts.NETWORK_FOLDER + "getallusers.php";
			HttpPost httppost = new HttpPost(connect);
			HttpResponse httpResponse = httpclient.execute(httppost);
			HttpEntity resEntityGet = httpResponse.getEntity();
			if (resEntityGet != null) {
				// do something with the response
				response = EntityUtils.toString(resEntityGet);
				Log.i("GET RESPONSE", response);
				// Log.d(
				response = response.trim();

			}
		} catch (Exception e) {
			// Log.d(
			e.printStackTrace();
			// finish();
		}
		return response;
	}

	public void postLeaderData(String result) {
		getDataFromJSON();